0

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.

3
  • What does VO stand for? Commented Jan 23, 2018 at 9:31
  • It is java object. I edited... Commented Jan 23, 2018 at 9:46
  • Are double quotes in val actually escaped like \"gurName\": \"sds\"? And can you show the result class you want to parse to? Commented Jan 24, 2018 at 18:40

1 Answer 1

1

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");    
}
Sign up to request clarification or add additional context in comments.

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.