私は文字列、オブジェクト形式で次の辞書があります。辞書のオブジェクトの値を取得するにはどのように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の反復を使用することができます見越し
これは機能します。ありがとうございました –
あなたは大歓迎です! –