2017-10-12 60 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到地圖 請幫我如何閱讀。 已經我能念想

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

你可以使用gson,檢查以下鏈接https://github.com/google/gson –

+1

什麼是'entry2'? –

+0

所有的json解析都是一樣的。從頂部開始。知道什麼是對象和數組。你可以在這裏沒有數組,所以應該很容易得到customerId,這是內部參考 –

回答

0

主文件你可以試試下面的代碼用於獲取$ REF值

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

輸出

abc.def.xyz。 1.json#