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

C# 如何在.Net中将json转换为json ld,c#,json-ld,C#,Json Ld,我正在尝试将json转换为json ld。到目前为止,我已经尝试了nuget的json-ld.net库(它是nuget3的一部分): 上下文资源: {"@context": { "ex": "http://example.org/", "term1": {"@id": "ex:term1", "@type": "ex:datatype"}, "term2": {"@id": "ex:term2", "@type": "@id"} }} 我的json存在且有效。它来自休息服务。(响应),并填充j

我正在尝试将json转换为json ld。到目前为止,我已经尝试了nuget的json-ld.net库(它是nuget3的一部分):

上下文资源:

{"@context": {
"ex": "http://example.org/",
"term1": {"@id": "ex:term1", "@type": "ex:datatype"},
"term2": {"@id": "ex:term2", "@type": "@id"}
}}
我的json存在且有效。它来自休息服务。(响应),并填充jtoken。但是,sz仅包含以下内容:

context":{"ex":"http://example.org/","term1":
{"@id":"ex:term1","@type":"ex:datatype"},"term2":
{"@id":"ex:term2","@type":"@id"}}}

微数据网是一个很好的平台。将.Net类转换为JSON-LD格式的Schema.org结构化数据


|

微数据.NET是一个很好的工具。将.Net类转换为JSON-LD格式的Schema.org结构化数据


|

我想我对这个问题的理解是错误的。使用GitHub上的JsonLD.Entities可以轻松完成从POCO到JSON-LD的转换。如果我从POCO开始,或者将JSON转换为POCO,那么这很容易实现

var person = new Person
{
Id = new Uri("http://t-code.pl/#tomasz"),
Name = "Tomasz",
LastName = "Pluskiewicz"
};
var @context = JObject.Parse("{ '@context': 'http://example.org/context/Person' }");
var contextProvider = new StaticContextProvider();
contextProvider.SetContext(typeof(Person), @context);

// when
IEntitySerializer serializer = new EntitySerializer(contextProvider);
dynamic json = serializer.Serialize(person);

我想我把问题框错了。使用GitHub上的JsonLD.Entities可以轻松完成从POCO到JSON-LD的转换。如果我从POCO开始,或者将JSON转换为POCO,那么这很容易实现

var person = new Person
{
Id = new Uri("http://t-code.pl/#tomasz"),
Name = "Tomasz",
LastName = "Pluskiewicz"
};
var @context = JObject.Parse("{ '@context': 'http://example.org/context/Person' }");
var contextProvider = new StaticContextProvider();
contextProvider.SetContext(typeof(Person), @context);

// when
IEntitySerializer serializer = new EntitySerializer(contextProvider);
dynamic json = serializer.Serialize(person);

您的上下文资源正确吗?我在这个网站上试过,它无法解析,我有简单的json。我需要将其转换为json ld。如果我把简单的json放在操场上,结果也是一样。如何进行转换?我尝试使用此上下文稍微修改了您的上下文,并对其进行了解析,但我不确定它是否是您想要的:{“@context”:“@type”:“WebSite”,“ex”:“term1”:{“@id”:“ex:term1”,“@type”:“ex:datatype”},“term2”:{“@id”:“ex:term2”,“@type”:“@id”}您的上下文资源正确吗?我在这个网站上试过,它无法解析,我有简单的json。我需要将其转换为json ld。如果我把简单的json放在操场上,结果也是一样。如何进行转换?我尝试使用此上下文稍微修改了您的上下文,并对其进行了解析,但我不确定它是否是您想要的:{“@context”:“@type”:“WebSite”,“ex”:“term1”:{“@id”:“ex:term1”,“@type”:“ex:datatype”},“term2”:{“@id”:“ex:term2”,“@type”:“@id”}工作起来很有魅力!工作起来很有魅力!