2017-07-17 8 views
0

私はこのようなJSON何か持っている:JSON.NET - 取得ネストされた値

{ 
    "key": "Target", 
    "value": { 
     "__type": "Entity:http://schemas.microsoft.com/xrm/2011/Contracts", 
     "Attributes": [ 
     { 
      "key": "prioritycode", 
      "value": { 
      "__type": "OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts", 
      "Value": 1 
      } 
     }, 
     { 
      "key": "completeinternalreview", 
      "value": false 
     }, 
     { 
      "key": "stepname", 
      "value": "10-Lead" 
     }, 
     { 
      "key": "createdby", 
      "value": { 
      "__type": "EntityReference:http://schemas.microsoft.com/xrm/2011/Contracts", 
      "Id": "ca2ead0c-8786-e511-80f9-3863bb347b18", 
      "KeyAttributes": [], 
      "LogicalName": "systemuser", 
      "Name": null, 
      "RowVersion": null 
      } 
     } 
     ] 
    } 
    } 

をどのようにキーの値を検索して、キー/値のためTOKE?

public class MyValue 
{ 
    [JsonProperty("Attributes")] 
    public List<KeyValuePair<string, object>> Attributes { get; set; } 
} 

あなたは、単に文字列をデシリアライズすることができます

例:私はあなたがあなたのJSONからオブジェクトを属性を表すために、このようなC#クラスを持っていると仮定すると、キーと値のペア「completeinternalreview」

+0

JSON文字列を逆シリアル化した後は、単純なLINQクエリを実行できる 'value.Attributes'オブジェクトがあります。 – danielspaniol

答えて

0

を取得したいです:

var result = JsonConvert.DeserializeObject<KeyValuePair<string, MyValue>>(jsonString); 

し、その後で正しいキーと値のペアを見つける:

var kvp = result.Value.Attributes.Find(a => a.Value == "completeinternalreview"); 
+0

素晴らしい、まさに私が必要なもの! – Stanza

関連する問題