str=你的字符串
JSONObject out = JSON.parseObject(str);
JSONArray childList = JSON.parseArray(out.get("Rule"));
for(int i=0;i<childList.size();i++){
JSONObject childListElement = childList.get(i);
JSONArray childChildList = JSON.parseArray(childListElement.get("fruitInfo"));
for(int j=0;j<childChildList.size();j++){
JSONObject childChildListElement = childChildList.get(j);
///////////////////////////////////////
childListElement.put(" ",childChildListElement.get("apple"))
/////////////////////////////////////
}
}
基本就是这个逻辑了,没测试,用的fastjson解析json字符串,最里层的是要赋值的。
不过这样做感觉只能每层数组只有一个元素吧,多了会出现下面这样,无法都拿出来,根据具体需要改上面代码就行了。
"fruitInfo": [
{
"apple": "sweet",
"pineapple": "sour",
},
{
"apple": "sweet2",
"pineapple": "sour2",
},
]