-1

I'm performing a query on my server which returns tree information in JSON format. Below

[{"leaf": 0, "context": {}, "text": "ABC-1-6-1", "expandable": 1, "id": "1.1.2.202.ABC-1-6-1", "allowChildren": 1}]

I was having play round with json-simple library and can parse it ok using JSONParser if can get the above info in String format i.e.

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}";

Any help would be great!

daverocks
  • 2,293
  • 5
  • 19
  • 23

2 Answers2

0

If you want to convert JSON to java then use gson. it is very simple.

  Person fromJson = new Gson().fromJson(json, Person.class);// this will convert json to java object
        fromJson.setAge(15);
        fromJson.setName("json");
        fromJson.setEmail("email@gmail.com");
        fromJson.setMob("4657576876");

        json = new Gson().toJson(fromJson);// this will convert java to json string like this {"name":"json","age":15,"email":"email@gmail.com","mob":"4657576876"}

https://sites.google.com/site/gson/gson-user-guide

Refer the following link for json array convertion

serialize and deserialize json array

Community
  • 1
  • 1
Parvathy
  • 2,275
  • 3
  • 24
  • 39
0

You have many JSON parsers for Java

Stardust
  • 1,115
  • 6
  • 22
  • 33