-4

I'm new learner of java. can anyone assist me how to parse the following json . I want to get data id from the below code :

{"room": {"id": "3","temp": "29"}}
user1865629
  • 91
  • 1
  • 1
  • 5

3 Answers3

0

I've used GSON to good effect.

chooban
  • 9,018
  • 2
  • 20
  • 36
0

Take a look at JSON in Java. It can help you convert JSON strings to java objects and vice versa.

0

I've used GSON http://code.google.com/p/google-gson/ and I believe it's the best,

First you create a class to hold your JSON structure

Class Room {
    int id;
    int temp;
}

And then you parse your string into a json like this

Gson gson = new Gson();
Room room = gson.fromJson(jsonString, Room.class);
Badr Ghatasheh
  • 968
  • 2
  • 7
  • 19