public static void main(String[] args){ String goodFromat="[{\"spec_name\": \"尺码\",\"value\": [{\"spec_value_name\": \"橙色2\"}, {\"spec_value_name\": \"橙色2\"}]}]"; JSONArray jsonarr= JSONArray.parseArray(goodFromat); for(int i =0; i < jsonarr.size(); i++){ JSONObject jsonObject = jsonarr.getJSONObject(i); jsonObject.put("spec_Id",5654); System.out.println(jsonObject); System.out.println(jsonObject.get("spec_name")); JSONArray jsonarr1 =JSONArray.parseArray(jsonObject.get("value").toString()); for(int j =0; j < jsonarr1.size(); j++){ JSONObject jsonObject1 = jsonarr1.getJSONObject(i); jsonObject1.put("id",222); System.out.println(jsonObject1); System.out.println(jsonObject1.get("spec_value_name")); } jsonObject.put("value",jsonarr1); System.out.println("jsonObject3"+jsonarr1.toJSONString()); } System.out.println(jsonarr.toJSONString()); }
使用JSONArray.parseArray();解析数组套数组json串
最新推荐文章于 2023-04-10 23:50:00 发布