让我有一个JSON
如下所示的对象
{"Name":"Manu","Age":"25","Address":""}
更新
读取 json 对象并需要更新地址字段,如下所示
{"Name":"Manu","Age":"25","Address":"XXXX"}
谁能告诉我如何在JSON
使用中更新地址详细信息java
我的代码
JSONObject rec = new JSONObject(data);
String name = rec.getString("Name");
String age = rec.getString("Age");
String add = rec.getString("Address");
现在如何向地址字段添加一些信息
更新 1
String jsonstring="{Name:Manu,Age:25,Address:''}";
JSONObject object=new JSONObject(jsonstring);
JSONObject childobject=object.getJSONObject("Address");
JSONObject modifiedjson=new JSONObject();
modifiedjson.put("type",childobject.get("type"));
modifiedjson.put("value","newvalue");
例外
Exception in thread "main" org.json.JSONException: JSONObject["Address"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:557)
at kotouch.Sample.main(Sample.java:59)
Java Result: 1