- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将一个大型 JSON-LD 文件作为我用 Java 编写的算法的输入。因此,我打算为此使用 JSONLD-JAVA。
JSONLD-JAVA页面显示了一个读取 JSON-LD 文件的示例,但不是用于导航或遍历它,也不是访问其中的单个对象。相反,它指的是 JSON-LD和 JSON-LD API有关特定可能操作的详细信息的规范。
然而,JSON-LD 规范只是定义了 JSON-LD 的语法和语义,并没有说明如何访问它们,当然也不应该,它只是格式的规范。我期望在 JSON-LD API 规范中描述这种操作,但它只描述了将整个 JSON-LD 文件转换为不同形式(压缩、扩展、展平和转换为 RDF)的操作。它似乎不包括访问对象的操作(例如,访问对象的键值对)。
所以我猜我们应该读取 JSON-LD 文件并将其展开或展平,然后将其作为纯 JSON 进行访问。但是 JSONLD-JAVA 方法只返回 Object
的实例,所以我不清楚如何使用这些对象来获取 JSON 键值对。唯一的异常(exception)似乎是 frame
方法,它返回一个 Map,但我不太清楚什么是框架。 JSON-LD 规范不包含“框架”一词,而且 JSON-LD API 规范有非常简洁的解释,似乎无助于理解如何访问对象的键值对。
我只有来自 JSONLD-JAVA 方法的 Object 实例的事实也使得它看起来很难使用一些 JSON 库来使用它们,除非我使用一些知道这些对象的内部格式的 JSON 库由JSONLD-JAVA形成,但是JSONLD-Java的页面没有提到任何这样的库。
我期望能够读取 JSON-LD 文件,然后在 Java 中以编程方式访问或操作它,并拥有与主要概念相对应的 Java 类,例如 JSONLDObject
提供其键值对的方法。
当我阅读以上几页时,我觉得它们是为那些已经知道一些我不知道的事情的人准备的。所以也许我错过了什么。否则,是否有关于使用 JSONLD-JAVA 或什至仅使用 JSONLD API 来遍历对象的教程?
最佳答案
如果您阅读链接到的 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));
第二条评论很有趣,所以让我为您突出显示:
Read the file into an
Object
(The type of this object will be aList
,Map
,String
,Boolean
,Number
ornull
depending on the root object in the file).Object jsonObject = JsonUtils.fromInputStream(inputStream);
关键是 JSONLD 是 JSON,当你像上面那样将它加载到内存中时,你可以通过转换 Object
来导航 JSON 结构视情况而定。
让我们看一下来自 JSON-LD specification 的示例 #3:
{
"@context":
{
"name": "http://schema.org/name", // ← This means that 'name' is shorthand for 'http://schema.org/name'
"image": {
"@id": "http://schema.org/image", // ← This means that 'image' is shorthand for 'http://schema.org/image'
"@type": "@id" // ← This means that a string value associated with 'image' should be interpreted as an identifier that is an IRI
},
"homepage": {
"@id": "http://schema.org/url", // ← This means that 'homepage' is shorthand for 'http://schema.org/url'
"@type": "@id" // ← This means that a string value associated with 'homepage' should be interpreted as an identifier that is an IRI
}
}
}
因此,如果您想要 @id
的 image
值,您可以这样做:
Map<String, Object> root = (Map) jsonObject;
Map<String, Object> context = (Map) root.get("@context");
Map<String, Object> image = (Map) root.get("image");
String imageId = (String) image.get("@id");
关于java - 如何使用 JSONLD-JAVA 遍历、导航和访问 JSON-LD 文件中的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715194/
ion-nav-view 嵌套有一个奇怪的问题。当我在浏览器中加载应用程序时,我可以看到 URL 正在更改为 /app/menu,但页面上没有出现 menu.html 中的内容。页面是空白的。 以下是
运行截图如下: 源码如下: CN_TEST1
我正在开发一个示例reactjs应用程序(在学习过程中)。我有一个页面,其中列出了用户列表和一个用于添加新用户的添加按钮。 当我单击添加按钮时,我应该导航到用户表单以创建新用户。 单击用户表单中的提交
我的导航栏中的导航链接有问题。首先,它没有在导航栏中间对齐,如下所示: 另一部分是,我正在使用填充来执行此操作,因此如果我放置除“测试”以外的任何内容或将其放在不同的情况下,等等。它会重复该框。代码预
基本上,我有一个网站,我正在尝试使用 ajax 导航构建它,以便它获取网页并将它们加载到同一页面中。问题是当我正常放入内容时它工作正常但是当我尝试将内容添加到外部文档并从导航中访问它时框拆分你可以在这
以下站点左侧菜单的导航使用 CSS 进行鼠标悬停链接。 PVH 当我获取导航代码并将其设为单独的页面时。然后鼠标悬停链接不起作用。可能是什么原因? Test 最佳答案 可能... 对此事有话要说
一 问题描述 标准的 Web 浏览器包含在最近访问过的页面中向后和向前移动的功能。实现这些特性的一种方法是使用双栈来跟踪前后移动可以到达的页面。 Web 导航支持下面的命令。 后退页面:将当前页面推到
我想有条件地导航到某个页面。如果某些条件为真,我想导航到其他页面,否则我想留在同一页面上。我有类似的东西:- 在 bean.navigate 我有类似的东西:- public String navi
问题:有没有办法让按钮在用户控件中表现得像超链接? 我已经搜索了几天,但没有找到解决此问题的人。如何使用按钮在 WPF 应用程序中导航?具体来说,如何使用户控件内的按钮在其主机框架中导航?请记住,用户
我尝试使用 Android Navigation 组件并遇到了回栈问题。 我有 fragment A,B。 我写的: Navigation.findNavController(view).naviga
我有一个父布局,并从该子站点派生而来。 父级布局具有一个导航,每个导航点代表一个子站点。 如何在父布局中突出显示当前查看的子站点? 如果看起来如何? 最佳答案 可能不是最好的选择,但这是基于路由名称的
我正在开发Blazor服务器端应用程序。熟悉Blazor的任何人都在左侧的NavBar中填充超链接,并以特殊的CSS类进行装饰。我的问题是,如果任何内容都已编辑,我将试图停止导航并在一个特定页面上显示
我是 flutter 的新手,我正在开发一个具有多个屏幕的应用程序。 我想知道如何阻止 flutter 创建同一路线的多个屏幕, 例如我有 第1页和 第2页 ,如果我单击按钮导航到第 2 页并再次单击
我们的设计师创建了一个类似于上面屏幕的布局。主要思想是创建一个只有一个屏幕的应用程序,当您点击一个按钮时,屏幕的红色部分会发生变化(即 2 个文本框而不是 1 个文本框)。这个应用程序将是一个多平台应
有人可以解释为什么从pageE返回时不打印efeioi吗? 页面A Navigator.pushNamed(context, PageB.ROUTE).then((onValue) {
我需要在 iOS 应用程序中创建一个导航,如下图所示。 它包含一个标签栏和一个侧边菜单。 问题是正确的导航菜单按钮,应该在所有选项卡中都可见。甚至每个选项卡的所有内部屏幕。 当用户从侧面菜单中选择一个
这个问题在这里已经有了答案: Vim: move around quickly inside of long line (8 个答案) 关闭 8 年前。 我正在用 vim 编辑一个文本文件,我已经使
我很困惑,如何执行操作来创建从用户位置到用户选择/点击图钉覆盖层的图钉覆盖层(谷歌位置)的路线/导航。这是我的 map Activity ,它将显示我的 map 。 public class Plac
我正在使用 jQuery 函数 .animate 来一一突出显示导航链接。他们在 ul 中。我可以让它工作,只是想知道是否有一种方法可以缩短我的代码,这样我就不必单独突出显示每个项目。提前致谢 $(d
我正在创建一个带有“ anchor 导航”的网站,就像 Facebook 和谷歌邮件一样。我已经让它工作了,但还不完全。当我加载带有 #contact 之类的页面时,除非我单击它的链接,否则它不会加载
我是一名优秀的程序员,十分优秀!