Hello everyone, I am a newbie and my English is bad. Then i have a file JSON
"body": { "content": [ { "endIndex": 1, "sectionBreak": { "sectionStyle": { "columnSeparatorStyle": "NONE", "contentDirection": "LEFT_TO_RIGHT", "sectionType": "CONTINUOUS" } } }, { "endIndex": 75, "paragraph": { "elements": [ { "endIndex": 75, "startIndex": 1, "textRun": { "content": "This is an ordinary paragraph. It is the first paragraph of the document.\n", "textStyle": {} } } ], "paragraphStyle": { "direction": "LEFT_TO_RIGHT", "namedStyleType": "NORMAL_TEXT" } }, "startIndex": 1 },
So I want to get "content": "This is an ordinary paragraph. It is the first paragraph of the document.\n" from JSOn using JAVA. But i can't get it. Pls help me get it. Thanks
I try using ArrayList but it don't active or my code is fault.
CodePudding user response:
You have to use one of the library: Jackson
or Gson
. There are more onese.
String json = "{}";
ObjectMapper mapper = new ObjectMapper();
MapType mapType = mapper.getTypeFactory().constructRawMapType(LinkedHashMap.class);
Map<String, Object> map = mapper.readValue(json, mapType);
List<Object> content = (List<Object>)map.get("content");
CodePudding user response:
Here is a guide to get the values of JSON objects. https://www.javatpoint.com/how-to-get-value-from-json-object-in-java-example