0

I have trying to store a JSON string in my solidity code string variable, it only stores the string on the constructor, but if try and store the same data in the function call it never saves it.

contract BOLData {

    string public SData;
    string public SCData;


    function BOLData(string S_Data) 
    { 
        SData= S_Data;
        SCData= '';
    } 
    function getSData() constant returns (string retVal) 
    { 
        return SData;
    }
    function setSCData(string SC_Data) 
    { 
        SCData = SC_Data; 
    } 
    function getSCData() constant returns (string retVal) 
    { 
        return SCData;
    }

}
1

Just gave it a try on Remix and seems to be working fine. using setSCData() does modify the value of SCData.

Maybe you are getting confused by the name of your variables... In the constructor you are setting SData but then the set function only deals with SCData, there's no function to update SData value.

  • yes pabloruiz55, i also tried in Remix, the real problem is that the JSON string in only accepted in the format "{\"_id\":\"5a1bec91f67fdc724cdb276c\"}", nothing else seems to work. How it works in the constructor only is still not understood. – user5740953 Nov 27 '17 at 12:45
0

try set the gas when you call the function such as “boldata.setSCData("you string", {from:eth.coinbase,gas:1000000});”

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.