如何阅读JSON文件的引用$ ref?
问题描述:
{
"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());
答
主文件你可以试试下面的代码用于获取$ 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#
你可以使用gson,检查以下链接https://github.com/google/gson –
什么是'entry2'? –
所有的json解析都是一样的。从顶部开始。知道什么是对象和数组。你可以在这里没有数组,所以应该很容易得到customerId,这是内部参考 –