我有以下代码片段,使用它我想将值存储在JSONObject中,以便可以迭代并在前端呈现它。
JSONObject dlCovs = jsonObject.getJSONObject("result").getJSONObject("cov_details");
Iterator x = dlCovs.keys();
while (x.hasNext()){
String key1 = (String) x.next();
String value1 = dlCovs.optString(key1);
dlCovs.put("covabbrv",key1);
dlCovs.put("dcIssuedt",value1);
dlCovs.put("vecatg",key1);
dlData.put("dlCovs", dlCovs);
}
/* dlCovs.put("covabbrv",cov);
dlCovs.put("issue_date",issue_date);*/
dlObj.put("status","valid");
dlData.put("dlCovs", dlCovs);
dlData.put("status","valid");
当我在while循环中迭代数据时,我遇到了java.util.concurrentModificationException异常。还有一种情况是在调试时,它会将值存储在dlData.put("dlCovs",dlCovs)中,但是一旦第二次迭代时就会抛出错误。我有以下JSON值:
"cov_details": {
"MCWG": "NA",
"3WTR": "NA",
"PSV BUS": "NA",
"LMV": "NA",
"INVCRG": "NA"
},
任何帮助都将不胜感激,提前致谢。输入代码如下:
dlCovs.put
,同时迭代dlCovs.keys()
。 - Andy Turner