I get msg.data
as JSON. How can I parse it in my contract to create variables in my contract with given values?
-
The answers to this two-year-old question might help: ethereum.stackexchange.com/questions/6121/… Also, here is a more recent article on this topic: steemit.com/json/@chrisdotn/a-json-parser-for-solidity– Ajoy BhatiaCommented May 29, 2018 at 19:21
Add a comment
|
1 Answer
It would be less expensive to parse the JSON outside the EVM and send the extracted values as parameters to your contract, if that is at all feasible in your design.
-
My exact problem is like this: I need a function to take variable number of arguments. Eg. in one call, it is { "name" : "xyz", "age" : 12 } and in other { "company_name" : "pqr", "address" : "some_address" } If I get the data via the msg.data then I need to parse it. Other option is to use
mapping
but seems it is not possible as function argument.– KumarCommented May 30, 2018 at 6:26 -
1Then, check out the JSON parser described in the Steemit article linked in my previous comment ( steemit.com/json/@chrisdotn/a-json-parser-for-solidity ). I have not used it but I read the article and it looks like what you need. Commented May 30, 2018 at 17:29