Chaincode参数错误:数组元素后的无效字符“:”

时间:2019-05-14 11:20:48

标签: arrays json hyperledger-fabric hyperledger

当尝试将json值作为输入(值)传递给超级账本调用链代码中的特定键时,出现以下错误:

Error: chaincode argument error: invalid character ':' after array element
Usage:
  peer chaincode invoke [flags]

Flags:
  -C, --channelID string               The channel on which this command should be executed
      --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
  -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
  -h, --help                           help for invoke
  -n, --name string                    Name of the chaincode
      --peerAddresses stringArray      The addresses of the peers to connect to
      --tlsRootCertFiles stringArray   If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag
      --waitForEvent                   Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully
      --waitForEventTimeout duration   Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s)

Global Flags:
      --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
      --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
      --clientauth                          Use mutual TLS when communicating with the orderer endpoint
      --connTimeout duration                Timeout for client to connect (default 3s)
      --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
  -o, --orderer string                      Ordering service endpoint
      --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer.
      --tls                                 Use TLS when communicating with the orderer endpoint
      --transient string                    Transient map of arguments in JSON encoding

传递的JSON字符串类似于

{
"gid": "INXXXXXXXXX6",
"json_data": {
    "issuer": {
        "issue_mode": "WEB",
        "issued_by": "abc@gmail.com",
        "issuer_name": "XYZ University",
        "issuer_logo": "XYZ.png"
    },
    "created_dt": "",
    "xid": "INXXXXXXXXX6",
    "xpaper": {
        "x_tag_id": "",
        "x_status": "VERIFY",
        "xDoc": {
            "title": "XYZ University",
            "ref_no": "A-3001",
            "validity_dt": "31-Dec-2300"
        },
        "Holder": [{
            "name": "Vijay",
            "image": "no_image.png",
            "img_hash": ""
        }],
        "xMedia": {
            "image": [{
                "name": "INXXXXXXXXX6.jpg",
                "type": "IMAGE",
                "is_private": "0",
                "x_hash": "7bde057df140b328cb4b467cfcf5cd98c5df4"
            }]
        },
        "XDetail": [{
            "DATE OF FIRST REGISTRATION": "12\/21\/1983",
            "FIRST NAME": "Vijay",
            "MIDDLE NAME": "Rao",
            "LAST NAME": "Mylari",
            "GENDER": "M",
            "DATE OF BIRTH": "19\/02\/1962.",
            "NATIONALITY": "INDIAN",
            "PAN NUMBER": "AXXXXXXXXX",
            "FATHER's NAME": "Mylari Rao",
            "MOTHER's NAME": "Yeshoda",
            "RESIDENTIAL ADDRESS": "Mumbai",
            "MOBILE NUMBER": "9876543210",
            "EMAIL ADDRESS": "vijayrao@gmail.com",
            "QUALIFICATION FOR REGISTRATION": "B.D.S.",
            "B.D.S. DEGREE PASSING DATE": "1\/12\/1983",
            "B.D.S. DEGREE AWARDING AUTHORITY \/ UNIVERSITY": "XYZ UNIVERSITY",
            "B.D.S. DEGREE REGISTRATION DATE": "21\/12\/1983",
            "P.G.DEGREE PASSING DATE": "Apr-85",
            "P.G.DEGREE AWARDING AUTHORITY \/ UNIVERSITY": "UNIVERSITY OF XYZ",
            "P.G.DEGREE REGISTRATION DATE": "02\/01\/2004.",
            "PG Speciality": "PERIODONTOLOGY",
            "Domicile Status (India\/Foreign)": "INDIA",
            "Date of Last Renewal": "2011"
        }]
    }
},
"type": "issue"

}

提供的json是有效的JSON字符串。数组元素的末尾没有任何“:”,但错误。有什么办法可以在PHP中解析

2 个答案:

答案 0 :(得分:1)

根据https://jsonlint.com,您的JSON无效,它返回:

Error: Parse error on line 41:
...: "AXXXXXXXXX",              "FATHER\'s NAME": "M
----------------------^
Expecting 'STRING', got 'undefined'

如果您替换这两个

"FATHER\'s NAME": "Mylari Rao",
"MOTHER\'s NAME": "Yeshoda",

通过

"FATHER\\'s NAME": "Mylari Rao",
"MOTHER\\'s NAME": "Yeshoda",

"FATHER's NAME": "Mylari Rao",
"MOTHER's NAME": "Yeshoda",

然后https://jsonlint.com对此感到满意。

我猜想\如果需要的话就需要转义。只需将其删除即可,因为'不需要转义。错误文本“ invalid character ':' after array element有点误导,因为它不是引起问题的:

答案 1 :(得分:0)

使用一个非常简单的示例,我已使用peer chaincode invoke命令将一个字符串化的JSON对象传递给chaincode函数,如下所示:

peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"Args":["initLedger","{\"property1\":\"one\",\"property2\":\"two\"}"]}'