-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse valid JSON array of objects and insert each object into a substrate pallet's StorageMap #20
Comments
i was able to do it with serde_json here https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7a066487d37870330444b0908115cacf
but serde_json doesn't work in my pallet as it causes error:
|
There are no any automatic serialize / deserialize support so you will need to construct JsonValue / match the generated JsonValue to work with the data. For serde_json, you should just need to disable std somewhere. |
i'm using lite-json again now because i can't figure out how to disable std to overcome that error with serde_json, for example, if i do the below, where the value of the key in the JSON file is an vector:
it appears to assign a value of type
|
Can you create a snippet with https://play.rust-lang.org to reproduce the error? |
i've reproduced the error in the latest commit in this DataHighway-DHX/node#238 (branch 'luke/rewards-allowance-new-offchain') unfortunately i can't replicate it using https://play.rust-lang.org/, because you can only use the top % of most used crates there, and lite_json doesn't appear to be in that and thus isn't available on the playground. |
@xlc i've been trying to use lite-json, and i noticed that you actually created it!
i'm want to use off-chain workers to query an external API endpoint in our code here where i've added the off-chain workers example code https://github.com/DataHighway-DHX/node/blob/luke/rewards-allowance-new-offchain/pallets/mining/rewards-allowance/src/lib.rs#L2684
i want to retrieve data in the following valid JSON format from the body of the http request response:
then iterate through each object in the array and whilst doing so i'll populate a data structure with each object's values and insert it into the pallet's storage where for each object in the that array i create a key (which is a tuple that contains both the start of the current date that we received the response, and the account_id that was in the response), and a value (which just contains the other two values received including the account_id's mining power
mpower
and the date that date was last updated off-chain)i'd also like to know how to serialize and deserialize that kind of object.
how may i do this with lite-json?
The text was updated successfully, but these errors were encountered: