本文介绍了编辑JSON字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON从服务器来如下
i have an json coming from server as below
{
"XXXX": {
"type": "RSS",
"value": ""
},
"YYYY": {
"type": "String",
"value": ""
},
"ZZZZ": {
"type": "String",
"value": ""
}
}
现在我需要在所有的XXXX,YYYY和ZZZZ的字段中添加SRING值
now i need to add the Sring value in field of all XXXX ,YYYY,and ZZZZ
使用eclipse IM,我需要改变XXXX价值和YYYY ZZZZ和的价值,我需要添加字段
im using eclipse and i need to change the value of "value" in XXXX and YYYY and ZZZZ and i need to add the field
{
"MMMM": {
"type": "Image",
"value": "a7e8bec0-87ed-11e2-aa2e-52540025ab96_2_1362746556"
}
}
在ZZZZ ..please让我知道该怎么做。
after ZZZZ ..please let me know how to do it.
推荐答案
试试这个
String jsonstring="{
"XXXX": {
"type": "RSS",
"value": ""
},
"YYYY": {
"type": "String",
"value": ""
},
"ZZZZ": {
"type": "String",
"value": ""
}
}";
JSONObject object=new JSONObject(jsonstring);
JSONObject childobject=object.getJSONObject("XXXX");
JSONObject modifiedjson=new JSONObject();
modifiedjson.put("type",childobject.get("type"));
modifiedjson.put("value","newvalue"); // Add new value of XXXX here
//
JSONObject mmjson=new JSONObject();
mmjson.put("type","image");
mmjson.put("value","a7e8bec0-87ed-11e2-aa2e-52540025ab96_2_1362746556"); // Add new value of MMM here
JSONObject newjson=new JSONObject();
newjson.put("MMMM",mmjson.toString());
newjson.put("XXXX",modifiedjson.toString());
newjson.put("YYYY",object.get("YYYY"));
newjson.put("ZZZZ",object.get("ZZZZ"));
这篇关于编辑JSON字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!