updev
updev

Reputation: 633

How to parse json feed in c#?

How can I parse json feed in c#?

I tried following so far:

         string fileurl = "http://itunes.apple.com/rss/customerreviews/id=123456789/json";

        var jsonStr = new WebClient().DownloadString(fileurl);

        JavaScriptSerializer serializer = new JavaScriptSerializer();
        var jsonObject = serializer.Deserialize<IDictionary<string, object>>(jsonStr);

Once i get Dictionary<string, object> dic1 = new Dictionary<string, object>(); using above code.

i iterate to get the value object[] as shown below.

        foreach (KeyValuePair<String, object> d in dic1)
        {
            var k = d.Key;
            var v = d.Value;
         }

Now the value is System.Object[] type so can anyone help me parse this object as shown in the below image? I'm new to this so any help would be great!

enter image description here

Upvotes: 1

Views: 1158

Answers (3)

Ed Power
Ed Power

Reputation: 8531

Perhaps the ServiceStack's JSON parser will help - it supports dynamic JSON.

Upvotes: 0

Matt Randle
Matt Randle

Reputation: 1893

I tend to use JSON.NET in situations like this. There is an example here where he parses a rss feed using LINQ,

http://james.newtonking.com/projects/json/help/

There is also the SelectToken method which queries the parsed JSON using a path syntax.

Upvotes: 2

CassOnMars
CassOnMars

Reputation: 6181

You're deserializing to the wrong type.

In your code,

JavaScriptSerializer serializer = new JavaScriptSerializer();
var jsonObject = serializer.Deserialize<IDictionary<string, object>>(jsonStr);

you specify that it needs to deserialize to type IDictionary<string, object>. Try matching the type to something other than object.

Upvotes: 0

Related Questions