2017-03-26 7 views
0

私は文字列、オブジェクト形式で次の辞書があります。辞書のオブジェクトの値を取得するにはどのようにC言語の文字列、オブジェクト>

Dictionary<string, object> responseList = null; 
    responseList = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response["Content"]); 

上記の辞書には、次のJSONデータがあります。

> { "_links": { 
>  "account": { 
>  "href": "https://api-uat.dwolla.com/accounts/ec297a2c-f681-417b-9668-8f3ebcd33060", 
>  "type": "application/vnd.dwolla.v1.hal+json", 
>  "resource-type": "account" 
>  }, 
>  "events": { 
>  "href": "https://api-uat.dwolla.com/events", 
>  "type": "application/vnd.dwolla.v1.hal+json", 
>  "resource-type": "event" 
>  }, 
>  "webhook-subscriptions": { 
>  "href": "https://api-uat.dwolla.com/webhook-subscriptions", 
>  "type": "application/vnd.dwolla.v1.hal+json", 
>  "resource-type": "webhook-subscription" 
>  }, 
>  "customers": { 
>  "href": "https://api-uat.dwolla.com/customers", 
>  "type": "application/vnd.dwolla.v1.hal+json", 
>  "resource-type": "customer" 
>  } } } 

私は "https://api-uat.dwolla.com/accounts/ec297a2c-f681-417b-9668-8f3ebcd33060" であるアカウントセクションのhrefを取得したいです。

var result = responseList["_links"]; 

このオブジェクト変数をさらに処理して、 "account"のhref値を取得するにはどうすればよいですか?敬具

foreach(var outer in responseList) 
{ 
foreach (var middle in (Dictionary<string, object>) outer.Value) 
{ 
    foreach (var inner in (Dictionary<string, string>) middle.Value) 
    { 
     Jsondata data = new Jsondata(); 
     data.href = inner["href"]; 
    }  
} 
} 

public class Jsondata 
{ 
public string href { get; set; } 
public string type { get; set; } 
public string resource{ get; set; } 
} 

あなたは、ネストされたJSONのためのforeachの反復を使用することができます見越し

答えて

1

にありがとう、

ThiyaguあるRajendran

**彼らが助け場合の答えとして回答をマークしてください。

+0

これは機能します。ありがとうございました –

+0

あなたは大歓迎です! –

1

JObjectをJSONの解析に使用しないのはなぜですか?あなたのJSONのサンプルをとり、データをオブジェクトに解析して次のように使用できました:

 JObject j = JObject.Parse(jsonData); 

     Console.WriteLine(j["_links"]["account"]["href"]); 
+0

甘くて短い解決策!ありがとう –

関連する問題