Работа с JSON файлами
{
userId: 32,
firstName: "Алексей",
lastName: "Голобурдин",
address: {
country: "Россия",
city: "Москва"
},
phone: "8 (905) 777 77 77"
}//import org.json.simple.JSONObject;
JSONObject resultJson = new JSONObject();
resultJson.put("name","foo");
resultJson.put("num",new Integer(100));
resultJson.put("is_vip",new Boolean(true));
resultJson.put("nickname",null);
System.out.print(obj.toString());
// {"name": "foo", "num": 100, "is_vip": true, "nickname: null}
JSONArray ar = new JSONArray();
JSONObject obj = new JSONObject();
JSONObject resultJson = new JSONObject();
ar.add("first");
ar.add(new Integer(100));
obj.put("one", "two");
obj.put("three", "four");
resultJson.put("paramsArray", ar);
resultJson.put("paramsObj", obj);
resultJson.put("paramsStr", "some string");
System.out.print(obj.toString());
// {"paramsArray": ["first", 100],
// "paramsObj": {"one": "two", "three": "four"},
// "paramsStr": "some string"}Last updated