[英]JSON - how to parse it properly?
I got problem parse JSON data in proper format. 我在解析正确格式的JSON数据时遇到问题。 This is my JSON data.
这是我的JSON数据。 I just want to grab
beneAcctNumber
from the data. 我只想从数据中获取
beneAcctNumber
。
{
"restFilteredInterRegisteredAccounts": {
"101010-BPD Bali-Permata ALTO": {
"beneficiaryNote": null,
"beneficiaryName": "Permata ALTO",
"accountCurrency": "IDR",
"paymentType": null,
"beneficiaryIdType": null,
"transferLimit": null,
"beneficiaryResident": null,
"accountLimit": 5.0E7,
"bankName": "BPD Bali",
"lastModTime": null,
"ibInterAcctRef": null,
"bankCode": "000129",
"beneficiaryEmail": null,
"ibInterAcctStrcol1": null,
"ibInterAcctStrcol2": null,
"userId": 1551,
"beneAcctNumber": "101010",
"beneficiaryId": null,
"mobileNumber": null
}
},
}
I got undefined value after retrieved it. 检索后得到未定义的值。 My tryout for this one.
我对此的试用。
restFilteredInterRegisteredAccounts[0].beneAcctNumber
Please advice. 请指教。
restFilteredInterRegisteredAccounts is not an array, so [0] is undefined... something like this would do it (assuming jsonObject is holding the json data): restFilteredInterRegisteredAccounts不是数组,因此[0]是未定义的……类似的事情可以做到这一点(假设jsonObject持有json数据):
jsonObject["restFilteredInterRegisteredAccounts"]["101010-BPD Bali-Permata ALTO"]["beneAcctNumber"] jsonObject [“ restFilteredInterRegisteredAccounts”] [“ 101010-BPD Bali-Permata ALTO”] [“ beneAcctNumber”]
restFilteredInterRegisteredAccounts has objects inside and this is not an array so index can not be used to get value. restFilteredInterRegisteredAccounts内部有对象,它不是数组,因此不能使用索引获取值。 "101010-BPD Bali-Permata ALTO" behaves as a property restFilteredInterRegisteredAccounts.
“ 101010-BPD Bali-Permata ALTO”表现为属性restFilteredInterRegisteredAccounts。 i am not sure if "101010-BPD Bali-Permata ALTO" is valid property name.
我不确定“ 101010-BPD Bali-Permata ALTO”是否为有效的属性名称。 ideally this should not contain spaces in between.
理想情况下,两者之间不应包含空格。 if this works then try
如果这有效,请尝试
restFilteredInterRegisteredAccounts["101010-BPD Bali-Permata ALTO"].beneAcctNumber
restFilteredInterRegisteredAccounts [“ 101010-BPD Bali-Permata ALTO”]。beneAcctNumber
var da = {
"restFilteredInterRegisteredAccounts": {
"101010-BPD Bali-Permata ALTO": {
"beneficiaryNote": null,
"beneficiaryName": "Permata ALTO",
"accountCurrency": "IDR",
"paymentType": null,
"beneficiaryIdType": null,
"transferLimit": null,
"beneficiaryResident": null,
"accountLimit": 5.0E7,
"bankName": "BPD Bali",
"lastModTime": null,
"ibInterAcctRef": null,
"bankCode": "000129",
"beneficiaryEmail": null,
"ibInterAcctStrcol1": null,
"ibInterAcctStrcol2": null,
"userId": 1551,
"beneAcctNumber": "101010",
"beneficiaryId": null,
"mobileNumber": null
}
}, "somethingelse" : "whatever"
};
To access property (here beneAcctNumber
) we will use 要访问属性(此处为
beneAcctNumber
),我们将使用
da.restFilteredInterRegisteredAccounts['101010-BPD Bali-Permata ALTO'].beneAcctNumber
I already found the correct answer. 我已经找到正确的答案。 100% working.
100%工作。
var output = "";
$.each(restFilteredInterRegisteredAccounts, function(index, item) {
output += item.beneAcctNumber ;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.