通过 Google 搜索,我找到了一个库,它将把 JSON-LD 解码为“未定义” Object。
// Open a valid json(-ld) input file
InputStream inputStream = new FileInputStream("input.json");
// Read the file into an Object (The type of this object will be a List, Map, String, Boolean,
// Number or null depending on the root object in the file).
Object jsonObject = JsonUtils.fromInputStream(inputStream);
// Create a context JSON map containing prefixes and definitions
Map context = new HashMap();
// Customise context...
// Create an instance of JsonLdOptions with the standard JSON-LD options
JsonLdOptions options = new JsonLdOptions();
// Customise options...
// Call whichever JSONLD function you want! (e.g. compact)
Object compact = JsonLdProcessor.compact(jsonObject, context, options);
// Print out the result (or don't, it's your call!)
System.out.println(JsonUtils.toPrettyString(compact));
Run Code Online (Sandbox Code Playgroud)
https://github.com/jsonld-java/jsonld-java
显然,它也可以从字符串中获取它,就像从文件或其他来源读取它一样。object我不知道你如何访问 的内容。不过,该文档似乎还算不错。
这似乎是一个活跃的项目,因为最后一次提交是在 4 天前,并且有 30 名贡献者。许可证是 BSD 3-Clause(如果这对您有任何影响的话)。
我与这个项目没有任何关系。我不是作者,也没有提出任何拉取请求。这只是我发现的东西。
祝你好运,我希望这有帮助!