我試過了,但沒有正確的反應。我有以下 json。當型別為 @type 時,我想獲取 rdfs:label 的值:“owl:DbType and rdfs:class is given any class (GreenPlant/GreenPlantHistory)
例如:如果 @type":"owl:DbType 和類是 GreenPlant,則獲取 rdfs:label 的值,即 'Involved' 和 'Present'
我嘗試了以下查詢。但無法在其中添加類名。如何做到這一點。
詢問 : -
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"
}
}
uj5u.com熱心網友回復:
您的 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();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/424693.html
