Ethereum 合同中复杂对象的保存

Ethereum 合同中复杂对象的保存,ethereum,solidity,Ethereum,Solidity,我有一个用例,我需要在我的合同中保存以下示例数据 { Linkage : {"4" : "1", "77" : "59", "5" : "64", "4" : "464", "455" : "364", "25" : "364", "25" : "164", "55" : "8684", "85" : "864"}, UserId : "Some Id", } 字典显然是可扩展的(根和链接)。 我想发送数据并将其作为对象(c#和Java风格)检索。因此,当我从WEB3进行通信时

我有一个用例,我需要在我的合同中保存以下示例数据

{
    Linkage : {"4" : "1", "77" : "59", "5" : "64", "4" : "464", "455" : "364", "25" : "364", "25" : "164", "55" : "8684", "85" : "864"},
    UserId : "Some Id",
}
字典显然是可扩展的(根和链接)。 我想发送数据并将其作为对象(c#和Java风格)检索。因此,当我从WEB3进行通信时,我可以传递json。 可能吗

这就是我被卡住的地方

pragma solidity ^0.4.13;

contract Test{         
  struct UserProfile{       
    string UserId;
  }   

  UserProfile public Profile;

  function setProfile(UserProfile newProfile) public {
    Profile  = newProfile;
  }        
}

启动事务时,您还不能传递对象。只能通过内部函数调用()传入/返回结构

您必须使用基本类型传入数据,并将它们添加到内部结构中:

pragma solidity ^0.4.13;

contract Test { 
  struct UserProfile {
    string userId;
    mapping(uint256 => uint256) linkage;
  }   

  UserProfile public profile;

  function addLinkage(uint256 id, uint256 value) public {
    profile.linkage[id] = value;
  }
}

注意,如果您想批量传递链接,可以使用
addLinkage(uint256[]ids,uint256[]values)
您可以将对象序列化为字符串,solidity没有对象原语,而且可能永远不会,因为以太坊虚拟机的性质。

谢谢,从契约中检索怎么样?我可以从中检索一个好的json吗?