我正在从静止web服务的JSON数组响应这就好比如何通过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"}
}]
我试图遍历所有共同基金阵列属性来获取多个JSON对象其值。我已经尝试了这段代码片段,但它返回的错误 - “互助基金不存在”。在我的json文件中,一些对象是基金类型的,另一些是具有不同属性的其他类型,所以我必须迭代和区分两者。所以我不能使用getJSONObject(i)。您正在使用
JSONArray jsonArray=new JSONArray(response.getBody());
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject=jsonArray.getJSONObject("mutualFund");
}
你正在使用哪个json库? – 2017-04-25 16:26:52