Hyperledger错误:无效的JSON数据。找到一个不是字符串的值:[object Object]用于关系RelationshipDeclaration

时间:2019-05-18 10:18:39

标签: json hyperledger-fabric hyperledger-composer

使用REST API在http://localhost:3000/explorer上运行的Hyperledger作曲家

  

创建新的参与者学生时发生错误。由于->课程[]课程

     

{name = courses,type = com.pax.onlinecourse.Course,array = true,optional = false}

响应正文:

{
  "error": {
    "statusCode": 500,
    "name": "Error",
    "message": "Invalid JSON data. Found a value that is not a string: [object Object] for relationship RelationshipDeclaration {name=courses, type=com.pax.onlinecourse.Course, array=true, optional=false}",
    "stack": "Error: Invalid JSON data. Found a value that is not a string: [object Object] for relationship RelationshipDeclaration {name=courses, type=com.pax.onlinecourse.Course, array=true, optional=false}\n    at JSONPopulator.visitRelationshipDeclaration (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:268:31)\n    at JSONPopulator.visit (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:102:25)\n    at RelationshipDeclaration.accept (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/introspect/decorated.js:65:24)\n    at JSONPopulator.visitClassDeclaration (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:128:51)\n    at JSONPopulator.visit (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer/jsonpopulator.js:100:25)\n    at ParticipantDeclaration.accept (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/introspect/decorated.js:65:24)\n    at Serializer.fromJSON (/usr/local/lib/node_modules/composer-rest-server/node_modules/composer-common/lib/serializer.js:203:26)\n    at ensureConnected.then (/usr/local/lib/node_modules/composer-rest-server/node_modules/loopback-connector-composer/lib/businessnetworkconnector.js:635:43)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:118:7)"
  }
}

响应码:500

.cto文件:

namespace com.pax.onlinecourse

abstract participant Person identified by emailId {
  o String emailId
  o String name
  o Double balance default=1000.0
}

enum Education{
  o SLC
  o PLUS2
  o BACHELORS
  o MASTERS
}

participant Student extends Person {
  o Education education 
  --> Course[] courses
}

participant Teacher extends Person{
  o String[] skills 
}

asset Course identified by courseId{
  o String courseId
  o String courseName
  o Double amount
  o Integer enrollNo default=0
  --> Teacher teacher
}

transaction BuyCourse {
  --> Student student 
  --> Course course 
}

当我在在线composer-playground上部署.bna文件时,没有发生此错误。

1 个答案:

答案 0 :(得分:0)

我已经使用以下JSON数据成功生成了学生参与者。

Student 参与者的JSON格式。

{
  "$class": "org.example.basic.Student",
  "education": "SLC",
  "courses": [
    "resource:org.example.basic.Course#2"
  ],
  "emailId": "2",
  "name": "asas",
  "balance": 1000
}

再次,如果您遇到问题,请在此处发布JSON格式。

希望它将对您有帮助:)