0

How to parse this json response using Java

{
    "Name": {
        "name_description": "NIL",
        "date": "NIL"
    },
    "Age": {},
    "City": {},
    "SOAP": [
        ["content", "subtopic", "topic", "code"],
        ["I advised her to call 911, which he did.", "history of present illness", "subjective", "{}"]
    ]
}
soorapadman
  • 4,451
  • 7
  • 35
  • 47
S.Guha
  • 31
  • 2

2 Answers2

1

You'd have to use an external library like json-simple

Read more about it here

1

Use a library called org.json, it is honestly the best java json library.

for example:

import org.json.JSONObject;

private static void createJSON(boolean prettyPrint) {    
   JSONObject tomJsonObj = new JSONObject();
   tomJsonObj.put("name", "Tom");
   tomJsonObj.put("birthday", "1940-02-10");
   tomJsonObj.put("age", 76);
   tomJsonObj.put("married", false);

// Cannot set null directly
tomJsonObj.put("car", JSONObject.NULL);

tomJsonObj.put("favorite_foods", new String[] { "cookie", "fish", "chips" });

// {"id": 100001, "nationality", "American"}
JSONObject passportJsonObj = new JSONObject();
passportJsonObj.put("id", 100001);
passportJsonObj.put("nationality", "American");
// Value of a key is a JSONObject
tomJsonObj.put("passport", passportJsonObj);

if (prettyPrint) {
    // With four indent spaces
    System.out.println(tomJsonObj.toString(4));
} else {
    System.out.println(tomJsonObj.toString());
}

}

yfdgvf asdasdas
  • 170
  • 1
  • 9