0

i have following dictionary in string,object format.

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

In above dictionary I have following JSON data.

> {   "_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"
>     }   } }

I want to retrieve href of account section which is "https://api-uat.dwolla.com/accounts/ec297a2c-f681-417b-9668-8f3ebcd33060". I have retrieved object part of dictionary by

  var result = responseList["_links"];

How would I process this object variable further to retrieve href value of "account"? thank you in anticipation

2 Answers 2

2

You can use foreach iteration for nested Json

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; }
}

Sincerely,

Thiyagu Rajendran

**Please mark the replies as answers if they helps.

Sign up to request clarification or add additional context in comments.

Comments

1

Why not use JObject to parse the JSON? I took a sample of your JSON and was able to parse the data into an object and use it like the following:

        JObject j = JObject.Parse(jsonData);

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

1 Comment

Sweet and short solution! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.