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 Bhatia May 29 '18 at 19:21
Add a comment
|
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. – Abhinav May 30 '18 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. – Ajoy Bhatia May 30 '18 at 17:29