将JSON转换为java解析
问题描述:
我在我的服务器上执行查询,它以JSON格式返回树信息。下面将JSON转换为java解析
[{"leaf": 0, "context": {}, "text": "ABC-1-6-1", "expandable": 1, "id": "1.1.2.202.ABC-1-6-1", "allowChildren": 1}]
我在玩一轮JSON-简单的库,可以解析它使用OK如果JSONParser可以字符串格式即
String jsonString = "{\"leaf\": 0, \"context\": {}, \"text\": \"1.1.2.202.ABC-1-6-1\", \"expandable\": 1, \"id\": \"1.1.2.202.ABC-1-6-1\", \"allowChildren\": 1}";
任何帮助将是巨大的得到上面的信息!
答
如果你想将JSON转换为java然后使用gson。这很简单。
Person fromJson = new Gson().fromJson(json, Person.class);// this will convert json to java object
fromJson.setAge(15);
fromJson.setName("json");
fromJson.setEmail("[email protected]");
fromJson.setMob("4657576876");
json = new Gson().toJson(fromJson);// this will convert java to json string like this {"name":"json","age":15,"email":"[email protected]","mob":"4657576876"}
https://sites.google.com/site/gson/gson-user-guide
请参考以下链接JSON数组皈依
的问题是什么? – iMysak 2013-02-11 11:59:25
你的问题是什么? – 2013-02-11 12:03:24
我想解析JSON数据到java – daverocks 2013-02-11 12:03:40