【发布时间】:2017-04-25 16:03:39
【问题描述】:
我从 rest webservice 得到一个 json 数组作为响应,就像
[{
"mutualFund":{"fundCode":"XYZ","fundName": "Funds - Global Income
Fund (G)-SGD","isin":"LU0882574725","sedol":"1234"}},
{"brokers":{"fundID":"abcd","fundName":"Funds - Focus
Fund A-USD","isin":"LU0197229882","sedol":"6543"}
}]
我正在尝试遍历所有互惠基金数组属性以获取它们的值。我试过这个代码 sn-p 但它返回错误——“mutualFund 不存在”。在我的 json 文件中,一些对象属于共同基金类型,而一些对象属于具有不同属性的其他类型,因此我必须迭代并区分它们。所以我不能使用 getJSONObject(i)。
JSONArray jsonArray=new JSONArray(response.getBody());
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject=jsonArray.getJSONObject("mutualFund");
}
【问题讨论】:
-
你使用的是哪个 json 库?