迭代器JsonObject和JsonArray

时间:2016-08-05 09:19:39

标签: java arrays json jsonobject

下面是我的json。我需要在循环中获得两个字符串。如何在一个循环中? 有任何想法吗?感谢

这是我的代码部分:

JSONObject documentJSON = result.getJSONObject(SyncConsts.VALIDATION_ERRORS);

for(Iterator<String> iter = documentJSON.keys();iter.hasNext();) {
String key = iter.next();
}

实施例: 数量 - 错误的值,输入必须是数字

{"Errors":{"Quantity":{"wrongValue":"Wrong value, input must be a number"},"Amount":{"wrongValue":"Wrong value, input must be a number"},"Amount_name":{"wrongValue":"Wrong value, input must be a number"},"Amount_name_first":{"wrongValue":"Wrong value, input must be a number"}}}

1 个答案:

答案 0 :(得分:0)

试试这个

var json = {"Errors":{"Quantity":{"wrongValue":"Wrong value, input must be a number"},"Amount":{"wrongValue":"Wrong value, input must be a number"},"Amount_name":{"wrongValue":"Wrong value, input must be a number"},"Amount_name_first":{"wrongValue":"Wrong value, input must be a number"}}}
var k = {} ,j = 0;
for(i in json.Errors){
   k.j = (i + ' - ' + json['Errors'][i]['wrongValue']);
   j++;
}

现在你有单个循环的k变量