【问题标题】:Parsing JSON-LD in Android在 Android 中解析 JSON-LD
【发布时间】:2015-11-11 11:52:06
【问题描述】:

我正在构建一个 Android 应用程序。我正在使用的 API 以 JSON-LD 格式提供数据。我以前从未使用过 JSON-LD,因此不确定如何解析这些数据。我试过谷歌搜索,但似乎有 0 个结果结合了 Android 和 JSON-LD,只有 JSON。

我不确定如何在我的应用程序中使用此 API

请帮忙

【问题讨论】:

  • 可以使用gson解析:stackoverflow.com/questions/17188543/…
  • 我该怎么做呢?我已经下载了 Gson jar 文件但不知道如何使用它?你有一些代码示例我可以看一下吗?互联网上的信息并没有真正的帮助。

标签: android json api parsing json-ld


【解决方案1】:

你检查了吗 - 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 中在哪里设法解析 JSON-LD?
猜你喜欢
  • 2021-11-07
  • 2018-12-02
  • 2017-09-25
  • 1970-01-01
  • 2015-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
相关资源
最近更新 更多