Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何读取JSON文件的引用$ref?_Java_Json_Jackson - Fatal编程技术网

Java 如何读取JSON文件的引用$ref?

Java 如何读取JSON文件的引用$ref?,java,json,jackson,Java,Json,Jackson,。。。。。更多的钥匙。。。。。。。。 我需要进入$ref文件位置,并将json放入一个映射中 请帮助我学会阅读。 我已经能够像这样读取主文件了 { "description": "Something", "id": "abc.def.xyzjson#", "type": "object", "properties": { "triggerTime": { "description": "Something", "$ref": "abc.def.xy

。。。。。更多的钥匙。。。。。。。。 我需要进入$ref文件位置,并将json放入一个映射中 请帮助我学会阅读。 我已经能够像这样读取主文件了

{
  "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值

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

abc.def.xyz.1.json#


您可以使用gson,检查以下链接什么是
entry2
?所有json解析都是相同的。从顶部开始。知道什么是对象和数组。这里可以没有数组,所以应该很容易获得customerId,它是内部引用
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();
        }
    }
}