-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!

7
  • What the question is ? Commented Feb 11, 2013 at 11:59
  • What is your question ? Commented Feb 11, 2013 at 12:03
  • I want to parse the JSON data into java Commented Feb 11, 2013 at 12:03
  • @daverocks This is a json array will you give me the full string including name? Commented Feb 11, 2013 at 12:03
  • 1
    means you want to convert json to java object? Commented Feb 11, 2013 at 12:04

2 Answers 2

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 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

Refer the following link for json array convertion

serialize and deserialize json array

Sign up to request clarification or add additional context in comments.

Comments

0

You have many JSON parsers for Java

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.