Ошибка аргумента цепного кода: недопустимый символ ':' после элемента массива - PullRequest
0 голосов
/ 14 мая 2019

При попытке передать значение json в качестве ввода (значения) определенному ключу в hyperledger вызывает цепной код, появляется следующая ошибка:

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 ]

1 голос
/ 14 мая 2019

Согласно https://jsonlint.com, ваш JSON недействителен, он возвращает:

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

Если заменить эти 2

"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, немного вводит в заблуждение, потому что это не :, который вызывает проблему.

0 голосов
/ 15 мая 2019

Используя очень простой пример , я передал строковый объект JSON в функцию цепного кода с помощью команды peer chaincode invoke следующим образом:

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

...