Json 如何在hyperledger结构的链码中以参数形式发送对象数组

Json 如何在hyperledger结构的链码中以参数形式发送对象数组,json,hyperledger-fabric,hyperledger,hyperledger-chaincode,Json,Hyperledger Fabric,Hyperledger,Hyperledger Chaincode,我有一个如下所示的对象数组 [ {"name":"heamoglobin","reading":"12"}, {"name":"mrc","reading":"3.3"}, {"name":"hct","reading":"33"} ] 我需要将其作为chaincode函数的参数发送。我试着把整个阵列串起来 像这样 "[{\"name\":\"heamoglobin\",\"reading\":\"12\"},{\"name\":\"mrc\",\"reading\":\"3.3\"}

我有一个如下所示的对象数组

[ {"name":"heamoglobin","reading":"12"},
  {"name":"mrc","reading":"3.3"},
  {"name":"hct","reading":"33"} ]
我需要将其作为chaincode函数的参数发送。我试着把整个阵列串起来 像这样

"[{\"name\":\"heamoglobin\",\"reading\":\"12\"},{\"name\":\"mrc\",\"reading\":\"3.3\"},{\"name\":\"hct\",\"reading\":\"33\"}]"
但是没有得到成功的交易


有什么建议吗?

您必须将尚未转换为字符串的每个参数转换为字符串。比如:

wait contract.submitTransaction(“createReport”,uid,req.body.patientID,用户[0]。电子邮件,clinicProfile.centerName,date.toString(),JSON.stringify(数据));

然后适当地处理链码操作中的每个参数(解组数组等)。

必须将每个尚未字符串的参数转换为字符串。比如:

wait contract.submitTransaction(“createReport”,uid,req.body.patientID,用户[0]。电子邮件,clinicProfile.centerName,date.toString(),JSON.stringify(数据));

然后适当地处理链码操作中的每个参数(解组数组等)。

对于node.js,您是否尝试使用JSON.stringify函数?是的,但我仅在对象数组中使用它,尽管“wait contract.submitTransaction”(“createReport”),uid,req.body.patientID,用户[0]。电子邮件,clinicProfile.centerName,日期,JSON.stringify(数据))“我觉得参数将作为字符串传递。有6个论点。所以传递函数名+6个字符串。我假设uid、patientID和date不是字符串。所以这可能就是问题所在。然后必须正确解析链码中的这些参数。@ChintanRajvir我尝试将整个对象作为一个参数发送到链码中,如下面的wait contract.submitTransaction(“createReport”,JSON.stringify(uid,req.body.patientID,用户[0]。电子邮件,clinicProfile.centerName,日期,数据))不起作用这不是正确的方法。您必须将参数分别转换为字符串,如下面的回答中所示@kekomal。对于node.js,您是否尝试使用JSON.stringify函数?是的,但我仅在对象数组中使用它,尽管“wait contract.submitTransaction”(“createReport”),uid,req.body.patientID,用户[0]。电子邮件,clinicProfile.centerName,日期,JSON.stringify(数据))"我觉得这些参数将作为字符串传递。共有6个参数。因此,您可以传递函数名+6个字符串。我假设uid、patientID和date不是字符串。这可能就是问题所在。然后您必须在链码中正确解析这些参数。@ChintanRajvir我尝试将整个对象作为一个参数发送到链码,如下所示contract.submitTransaction(“createReport”,JSON.stringify(uid,req.body.patientID,user[0].email、clinicProfile.centerName、date、data)不起作用这不是正确的方法。您必须将参数分别转换为字符串,如下面的@kekomal回答中所示。