0

I want to store JSON input in my Smart Contract. Like

{ "name":"John" }

First I thought i could just handle it like a String, but it is not working because of the double quotes. Remix says, that there is an SyntaxError, because of an unhandled Token.

Example Code:

pragma solidity 0.5.0;

function tester(string memory x) public{
    string memory y=x;
}

Any suggestions?

1

This is just an issue with how Remix accepts input parameters. You won't see this problem when interacting with your smart contract from code.

That said, you can resolve the issue in Remix by quoting the string and escaping the JSON quotes, like so:

"{ \"name\":\"John\" }"
0

Encode/decode to/from UTF-8 client side. Looks like this: https://mothereff.in/utf-8

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.