i am converting a xml content into JSON content and the content is as follows
{
"response":
{
"seatlist":
{
"seat":
{
"balance":85694.6,"num":12
},
"seat":
{
"balance":85694.6,"num":12
}
},
"userid":"8970ca285d9c4e4d",
"seatnum":12,
"session":"online"
}
}
I am able to get the userid and seatnum in the following way
JSONObject response = json.getJSONObject("response");
out.setUserid(response.getString("userid"));
out.setBalance(Double.valueOf(response.getString("balance")));
Now the problem is i need to parse the following content and need to get "num" value
"seatlist":
{
"seat":
{
"balance":85694.6,"num":12
},
"seat":
{
"balance":85694.6,"num":12
}
}
here is my code i am using
JSONObject objList = response.getJSONObject("seatlist");
String n = String.valueOf(objList.getJSONObject("seat"));
if(objList.getJSONObject("seat").get("userId").equals(userId))
{
String num = String.valueOf(objList.getJSONObject("seat").get("num"));
out.setSeatNum(Integer.valueOf(num));
}
if i have one seat value i am able to get "num" value else i am getting JSON exception
Pls give me a suggestion in this.....