我有个问题。我编写了 JSON 解析代码,但它给了我一个错误。我不明白问题是什么。字符串结果是 JSON。我需要从 sum 中输出金额值。返回错误:“未找到 JSONObject[“sum”]。”
JSONObject json = new JSONObject(result);
JSONObject bpi = json.getJSONObject("sum");
String uuu = bpi.getString ("amount");
System.out.println(uuu);
{
"data": [
{
"txnId": 20071336083,
"personId": 1,
"date": "2020-10-21T20:10:56+03:00",
"errorCode": 0,
"error": null,
"status": "SUCCESS",
"type": "IN",
"statusText": "Success",
"trmTxnId": "403300256",
"account": "xxx",
"sum": {
"amount": 10,
"currency": 643
}
}
]
}