2017-10-12 1 views
-1
{ 
    "description": "Something", 
    "id": "abc.def.xyzjson#", 
    "type": "object", 
    "properties": { 
    "triggerTime": { 
     "description": "Something", 
     "$ref": "abc.def.xyz.1.json#" 
     "required": true 
    }, 
    "customerId": { 
     "type": "string", 
     "description": "Something", 
     "$ref": "abc.def.xyz.1.json#" 
    }, 

..... 더 많은 키 ........ $ ref 파일 위치로 이동하여 해당 json을지도에 넣어야합니다. 읽는 방법을 알려주세요. 이미 나는 당신은 $ 심판 값을

import org.json.simple.JSONArray; 
import org.json.simple.JSONObject; 
import org.json.simple.parser.JSONParser; 
public class Test{ 

    public static void main(String[] args) { 
     JSONParser parser = new JSONParser(); 

     try { 

      Object obj = parser.parse(new FileReader(
        "File location")); 
      JSONObject jsonObject = (JSONObject) obj; 
      JSONObject properties = (JSONObject) jsonObject.get("properties"); 
      JSONObject triggerTime = (JSONObject) properties.get("triggerTime"); 
      String ref = (String) triggerTime.get("$ref");//You can load this file to a map if required. 
      System.out.println(ref); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

출력을 얻기위한 코드 아래에 시도 할 수 있습니다

File jsonInputFile = new File("location"); 
System.out.println("Keys : " + entry2.getKey()); 
+0

gson을 사용할 수있는 경우 다음 링크를 확인하십시오. https://github.com/google/gson –

+1

'entry2 '란 무엇입니까? –

+0

json 구문 분석은 모두 동일합니다. 상단부터 시작하십시오. 객체와 배열이 무엇인지 파악합니다. 여기에 배열이 없으므로 customerId를 쉽게 얻을 수 있어야하며 내부 참조입니다. –

답변

0

같은 주요 파일을 읽을 수 있어요

abc.def.xyz입니다. 1.json #