0

I have a JSON response and i am extracting the body using getbody() command and storing the responses in list. because i am passing multiple JSON at a time so each response i am storing in list as string value. How can i extract that JSON using JAVA?

   response = request.post(route.payment());
            body = response.getBody();
            listofBody.add(body.asString());

above code is where i get the response and store that into list. before converting to JSON i can do response.jsonPath().getList("company"); to get the values

sarath
  • 107
  • 7

1 Answers1

0

To extract the element from JSON string you can use Google's Gson Library

Example:

JSONObject object = (JSONObject) JSONValue.parse(jsonString);
Set<String> keySet = object.keySet();
for (String key : keySet) {
    Object value = object.get(key);
    System.out.printf("%s=%s (%s)\n", key, value, value.getClass().getSimpleName());
}
Eklavya
  • 17,618
  • 4
  • 28
  • 57