Java 将JSON数组追加到JSONObject
如何附加:Java 将JSON数组追加到JSONObject,java,json,jsonobject,Java,Json,Jsonobject,如何附加: JSONObject jsonObj = new JSONObject("string"); jsonObj.toString(); "employees":[{"firstname":"stack","lastname":"overflow"}, {"firstname":"Happy","lastname":"Coding"}] 添加到上面的json对象 我想去 {"firstname":"Gloomy","lastname":"Sunday"} 请先自己研究一下,这个网
JSONObject jsonObj = new JSONObject("string");
jsonObj.toString();
"employees":[{"firstname":"stack","lastname":"overflow"}, {"firstname":"Happy","lastname":"Coding"}]
添加到上面的json对象
我想去
{"firstname":"Gloomy","lastname":"Sunday"}
请先自己研究一下,这个网站不是为你做计算机科学作业的。只是因为我需要一些代表
"employees":[{"firstname":"stack","lastname":"overflow"}, {"firstname":"Happy","lastname":"Coding"}, {"firstname":"Gloomy","lastname":"Sunday"}]
upon jsonObj.toString();
绑定到现有employees对象中,而不是创建新对象。您确定First代码示例会生成写在其末尾的字符串吗?这些数据来自哪里?
public class ex{
void example(){
try{
JSONObject jobj = new JSONObject("[{firstname:stack,lastname:overflow}]");
JSONObject jobj2 = new JSONObject("[{firstname:Happy,lastname:Coding}]");
JSONArray jarray = new JSONArray();
jarray.put(jobj);
jarray.put(jobj2);
}catch(JSONException e){
e.printStackTrace();
}
}
}
JSONObject jsonObj = new JSONObject();
JSONObject jo1 = new JSONObject("{"firstname":"Gloomy","lastname":"Sunday"}");
jsonObj.append("employees", jo1);