solidity中bytes[]数组如何转化为string数组?

//pragma solidity ^0.5.1;
pragma experimental ABIEncoderV2;
contract SearchPeopleInfo{

    uint _TransactionIDx;
    bytes[]  peoplelocations;
    bytes[]  existtime;

    struct PeopleInfo{
        uint peopleID;
        bytes peopleLocation;
        bytes ExistTime;
    }

    mapping(uint => PeopleInfo) public _peopleInfo;
    uint[] public _pendingPeopleInfo;

    function EnterInfo(uint peopleID, string memory stringpeopleLocation, string memory stringExistTime)public {  
        uint TransactionID=_TransactionIDx++;
        PeopleInfo memory peopleInfo;

        peopleInfo.peopleID=peopleID;
        peopleInfo.peopleLocation=bytes(stringpeopleLocation);//string to bytes
        peopleInfo.ExistTime=bytes(stringExistTime);//string to bytes
        _peopleInfo[TransactionID]=peopleInfo;

        _pendingPeopleInfo.push(TransactionID);

    }

    function searchInfo(uint _peopleID)public {
        delete peoplelocations;
        delete existtime;
        for (uint i=0;i<=_pendingPeopleInfo.length;i++){
        if (_peopleInfo[i].peopleID==_peopleID){
            peoplelocations.push(_peopleInfo[i].peopleLocation);
            existtime.push(_peopleInfo[i].ExistTime);
        }
        }
    }

    function getInfo( )public view returns (bytes[] memory,bytes[] memory){
         return(peoplelocations,existtime);

    }
}

函数getInfo()返回两个bytes[],分别为peoplelocations以及existtime,能否在solidity中将这两个bytes[]转化为字符串数组string[]?

请先 登录 后评论

最佳答案 2020-04-13 20:32

Bytes 可以直接转换为 String:使用 string() 依次对每个元素进行转换可以的string[]

请先 登录 后评论

其它 2 个回答

Yunoooooo - 博士在读
请先 登录 后评论
Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 2 关注
  • 0 收藏,6248 浏览
  • Yunoooooo 提出于 2020-04-05 16:20