修改JSONObject中的数据
replace方法
需要传入两个参数,第一个是key,第二个是value
JSONObject jsonObject1=new JSONObject();
jsonObject1.put("1","hello");
jsonObject1.replace("1","hello world");
修改完成之后hello就变成了hello world
遍历JSONObject
使用增强for循环,以下是示例代码:
try {
JSONObject jsonObject2 = RuleChecker.runByArrary(javacode, jsonObject1);//不用管,只是往jsonObject2里赋值
for(String str:jsonObject2.keySet()){
System.out.println(jsonObject2.getJSONObject(str));//拿到每个数据并输出
}
} catch (IOException e) {
e.printStackTrace();
}