如何在.Net中将json转换为json-ld

jlo*_*ail 1 c# json-ld

我正在尝试将 json 转换为 json-ld。到目前为止,我已经尝试过来自 nuget 的 json-ld.net 库(它是 nuget3 的一部分):https ://www.nuget.org/packages/json-ld.net/

var jtoken = JsonLD.Util.JSONUtils.FromString(response);
var options = new JsonLdOptions();
options.SetBase("http://json-ld.org/test-suite/tests/");
options.SetProduceGeneralizedRdf(true);
var context = JsonLD.Util.JSONUtils.FromString(Properties.Resources.jasonldcontext);
options.SetExpandContext((JObject)context);
var jtokenout = JsonLdProcessor.Compact(jtoken, context, options);
var sz = JSONUtils.ToString(jtokenout);
Run Code Online (Sandbox Code Playgroud)

上下文资源:

{"@context": {
"ex": "http://example.org/",
"term1": {"@id": "ex:term1", "@type": "ex:datatype"},
"term2": {"@id": "ex:term2", "@type": "@id"}
}}
Run Code Online (Sandbox Code Playgroud)

我的 json 存在且有效。它来自 REST 服务。(响应),并填充 jtoken。但是, sz 仅包含上下文:

context":{"ex":"http://example.org/","term1":
{"@id":"ex:term1","@type":"ex:datatype"},"term2":
{"@id":"ex:term2","@type":"@id"}}}
Run Code Online (Sandbox Code Playgroud)

小智 5

MXTires Microdata .NET 是一个不错的选择。将 .Net 类转换为 JSON-LD 形式的 Schema.org 结构化数据。

Nuget 链接| 使用链接