在java中解析json rest响应

在java中解析json rest响应,java,json,neo4j,Java,Json,Neo4j,我试图将java中neo4j的json输出解析为: Object obj = parser.parse(new FileReader("D:\\neo4j.json")); JSONArray json = (JSONArray) obj; System.out.println(json.size()); for (int i = 0; i < json.size(); i++) { JSONObject jsonObject = (JSONObject) json.get

我试图将java中neo4j的json输出解析为:

Object obj = parser.parse(new FileReader("D:\\neo4j.json"));

JSONArray json = (JSONArray)  obj;

System.out.println(json.size());

for (int i = 0; i < json.size(); i++) {
    JSONObject jsonObject = (JSONObject) json.get(i);
    String data = (String);   
    jsonObject.get("outgoing_relationships");
    String name = (String) jsonObject.get("name");
    System.out.println(data);
    System.out.println(name);       
}
问候,,
Jayendra

您可以尝试以下方法。在for循环中,将数据节点作为JSONObject获取。从该数据节点可以提取每个属性。我刚从数据中提取了母亲的名字

JSONObject data = (JSONObject) jsonObject.get("data");
final String motherName = (String) data.get("MOTHERS_NAME");

您使用什么库来解析JSON?我建议你使用

例如:要从映射中的文件中读取数据,可以编写如下方法

   @SuppressWarnings("rawtypes")
 public static Map toMap(Object object) throws JsonProcessingException{                   ObjectMapper mapper = new ObjectMapper();
    return mapper.convertValue(object, Map.class);
}
   @SuppressWarnings("rawtypes")
 public static Map toMap(Object object) throws JsonProcessingException{                   ObjectMapper mapper = new ObjectMapper();
    return mapper.convertValue(object, Map.class);
}