将数据按照结构体格式存储在链上,读取到的string类型的数据可以原格式返回,而uint类型数据为BN类型,

智能合约部分的结构体数据

struct  CarInfo{
        string  name;
        string  description;
        uint  reward;
        uint  waitTime;
        uint  longitude;
        uint  latitude;
    }

数据上传的处理逻辑

 event NewCarInfo();
    function addCarInfo(string memory _name,string memory _description,uint  _reward,  uint  _waitTime,uint  _longitude,uint  _latitude) public {
        CarInfo memory carInfo = CarInfo(_name,_description,_reward,_waitTime,_longitude,_latitude);
        CarInfos[msg.sender].push(carInfo);
        emit NewCarInfo();
    }

获取数据的console输出

Result
0: "4"
1: "5"
2: BN
length: (...)
negative: (...)
red: (...)
words: (...)
__ob__: Observer {value: BN, dep: Dep, vmCount: 0}
get length: ƒ reactiveGetter()
set length: ƒ reactiveSetter(newVal)
get negative: ƒ reactiveGetter()
set negative: ƒ reactiveSetter(newVal)
get red: ƒ reactiveGetter()
set red: ƒ reactiveSetter(newVal)
get words: ƒ reactiveGetter()
set words: ƒ reactiveSetter(newVal)
__proto__: Object
请先 登录 后评论

2 个回答

六天 - 区块链研发工程师
请先 登录 后评论
Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论