我有这个几乎是 JSON 的东西,里面只有类似于 JSON 的东西:
Oct 21 22:39:28 GMT [TRACE] (Carlos-288) org.some.awesome.LoggerFramework RID=8e9076-4dd9-ec96-8f35-bde193498f: {
"service": "MyService",
"operation": "queryShowSize",
"requestID": "8e9076-4dd9-ec96-8f35-bde193498f",
"timestamp": 1634815968000,
"parameters": [
{
"__type": "org.some.awsome.code.service#queryShowSizeRequest",
"externalID": {
"__type": "org.some.awsome.code.common#CustomerID",
"value": "48317"
},
"CountryID": {
"__type": "org.some.awsome.code.common#CountryID",
"value": "125"
},
"operationOriginalDate": 1.63462085667E9,
"operationType": "MeasureWithToes",
"measureInstrumentIdentifier": "595909-48d2-6115-85e8-b3aa7b"
}
],
"output": {
"__type": "org.some.awsome.code.common#queryShowSizeReply",
"shoeSize": {
"value": "$ion_1_0 '[email protected]'::'[email protected]'::{customer_id:\"983017317\",measureInstrumentIdentifierTilda:\"595909-48d2-6115-85e8-b3aa7b\",foot_owner:\"Oedipus\",toe_code:\"LR2X10\",account_number_token:\"1234-2838316-1298470\",token_status:VALID,country_code:GRC,measure_store_format:METRIC}"
}
}
}
正则表达式给了我 JSON 的开始,我尝试从那里解码。根据 https://jsonlint.com/,在那之后它是有效的 JSON。
那么为什么Python的JSON模块不解码呢?我得到这个错误:
Exception has occurred: JSONDecodeError
Expecting ',' delimiter: line 25 column 156 (char 992)
File "/Users/decoder/Downloads/json-problem.py", line 44, in read_json
d = json.loads(line)
^^^^^^^^^^^^^^^^
File "/Users/decoder/Downloads/json-problem.py", line 48, in <module>
print(read_json(TEST_LINE))
^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 25 column 156 (char 992)
第25行和第156个字符指向
\"
中的第一个output.shoeSize.value
。
但是为什么?该嵌入值只是粗略 JSON,但它不应该 尝试解码它,因为它是作为纯字符串给出的。引号被很好地转义,不会提前结束字符串。
raw_decode()
但同样失败了。我不明白。