如何从以下 json.I 尝试但没有正确输出中获取标签值
How to get label value from following json.I tried but no proper output
我已经试过了,但没有正确的反应。
我有以下 json.I 想要在类型为 @type 时获取 rdfs:label 的值": "owl:DbType 并且 rdfs:class 被赋予任何 class (GreenPlant/GreenPlantHistory)
Ex : If @type": "owl:DbType and class is GreenPlant, fetch rdfs:label's value that is 'Involved' & 'Present'
我已经尝试按照 query.But 无法在 that.How 中添加 classname 来做到这一点。
查询:-
List<string> jp = v1.Where(i => (string)i["@type"] == "owl:DbType")
.Select(i => (string)((JObject)i).Properties().First(x => x.Name == "rdfs:label").Value["@value"]).ToList();
{
"@id": "Ap:Involved",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlant"
},
"tag:std:label": {
"@value": "Involved"
},
"rdfs:label": {
"@value": "Involved"
},
"rdfs:range": {
"@id": "xsd:boolean"
}
},
{
"@id": "Ap:Present",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlant"
},
"tag:std:label": {
"@value": "Present"
},
"rdfs:label": {
"@value": "Present"
},
"rdfs:range": {
"@id": "xsd:boolean"
}
},
{
"@id": "Ap:UserName",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlantHistory"
},
"tag:std:label": {
"@value": "UserName"
},
"rdfs:label": {
"@value": "UserName"
},
"rdfs:range": {
"@id": "xsd:string"
}
},
{
"@id": "Ap:Name",
"@type": "owl:ObjType",
"rdfs:class": {
"@id": "Ap:GreenPlantHistory"
},
"tag:std:label": {
"@value": "Name"
},
"rdfs:label": {
"@value": "Name"
},
"rdfs:range": {
"@id": "xsd:string"
}
}
你的json无效,换成[]试试这个
var jsonParsed = JArray.Parse(json);
var found=FindValues(jsonParsed, "owl:DbType", "Ap:GreenPlant");
测试
Console.WriteLine(string.Join(",", found)); //Involved,Present
帮手
public List<string> FindValues(JArray jsonParsed, string strType , string strClass)
{
return jsonParsed.Where(i => (string)i["@type"] == strType
&& (string)i["rdfs:class"]["@id"] == strClass)
.Select(i => (string) i["rdfs:label"]["@value"]).ToList();
}
我已经试过了,但没有正确的反应。 我有以下 json.I 想要在类型为 @type 时获取 rdfs:label 的值": "owl:DbType 并且 rdfs:class 被赋予任何 class (GreenPlant/GreenPlantHistory)
Ex : If @type": "owl:DbType and class is GreenPlant, fetch rdfs:label's value that is 'Involved' & 'Present'
我已经尝试按照 query.But 无法在 that.How 中添加 classname 来做到这一点。
查询:-
List<string> jp = v1.Where(i => (string)i["@type"] == "owl:DbType")
.Select(i => (string)((JObject)i).Properties().First(x => x.Name == "rdfs:label").Value["@value"]).ToList();
{
"@id": "Ap:Involved",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlant"
},
"tag:std:label": {
"@value": "Involved"
},
"rdfs:label": {
"@value": "Involved"
},
"rdfs:range": {
"@id": "xsd:boolean"
}
},
{
"@id": "Ap:Present",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlant"
},
"tag:std:label": {
"@value": "Present"
},
"rdfs:label": {
"@value": "Present"
},
"rdfs:range": {
"@id": "xsd:boolean"
}
},
{
"@id": "Ap:UserName",
"@type": "owl:DbType",
"rdfs:class": {
"@id": "Ap:GreenPlantHistory"
},
"tag:std:label": {
"@value": "UserName"
},
"rdfs:label": {
"@value": "UserName"
},
"rdfs:range": {
"@id": "xsd:string"
}
},
{
"@id": "Ap:Name",
"@type": "owl:ObjType",
"rdfs:class": {
"@id": "Ap:GreenPlantHistory"
},
"tag:std:label": {
"@value": "Name"
},
"rdfs:label": {
"@value": "Name"
},
"rdfs:range": {
"@id": "xsd:string"
}
}
你的json无效,换成[]试试这个
var jsonParsed = JArray.Parse(json);
var found=FindValues(jsonParsed, "owl:DbType", "Ap:GreenPlant");
测试
Console.WriteLine(string.Join(",", found)); //Involved,Present
帮手
public List<string> FindValues(JArray jsonParsed, string strType , string strClass)
{
return jsonParsed.Where(i => (string)i["@type"] == strType
&& (string)i["rdfs:class"]["@id"] == strClass)
.Select(i => (string) i["rdfs:label"]["@value"]).ToList();
}