简体   繁体   中英

how to extract json body as string using java

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

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM