Reputation: 695
I am having a JSON Object as below:
{
"winame": "123",
"val": "[
{
"gurName": "sds",
"gurType": "",
"crNo": "",
"crissueDate": "",
"dob": "",
"gender": "",
"address": "",
"maritialStatus": "",
"cache": ""
}
]"
}
In which first key is value and second key contains the values of some Java Object type. How to parse the value of 'winame' and 'val' into that java Object.
Upvotes: 0
Views: 1869
Reputation: 967
You can parse JSON with any number of keys.
JSONObject obj = new JSONObject("xyz");
String winame= obj.getJSONObject("winame");
JSONArray arr = obj.getJSONArray("val");
for (int i = 0; i < arr.length(); i++)
{
String gurName = arr.getJSONObject(i).getString("gurName");
String gurType = arr.getJSONObject(i).getString("gurType");
String crNo = arr.getJSONObject(i).getString("crNo");
String crissueDate = arr.getJSONObject(i).getString("crissueDate");
String dob = arr.getJSONObject(i).getString("dob");
String gender = arr.getJSONObject(i).getString("gender");
String address = arr.getJSONObject(i).getString("address");
String maritialStatus = arr.getJSONObject(i).getString("maritialStatus");
String cache = arr.getJSONObject(i).getString("cache");
}
Upvotes: 1