我正在构建一个 Android 应用程序。我正在使用的 API 以 JSON-LD 格式提供数据。我之前从未使用过 JSON-LD,因此我不确定如何解析这些数据。我试过谷歌搜索,但似乎有 0 个结果结合了 Android 和 JSON-LD,只有 JSON。
我不确定如何在我的应用程序中使用这个 API
请帮忙
最佳答案
你检查过了吗 - https://github.com/jsonld-java/jsonld-java
这是一个示例代码
// 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));
关于android - 在 Android 中解析 JSON-LD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074180/