Iterating JObject

Jul 19, 2010 at 10:30 PM

Here is my JSON:

[{"aid":"10000192_-3",
  
"cover_pid":"10000130472_28286",
   "name":"Profile Pictures",
   "created":12795291,
   "modified":1272291,
   "description":"",
   "location":"",
   "link":"http:\/\/www.facebook.com\/album.php?aid=-3&id=1000013062",
   "size":1,
   "type":"profile",
   "object_id":0},

   {"aid":"1000013042_78",
    "cover_pid":"100009862_29171",
    "name":"Family Pictures",
    "created":19548161,
    "modified":1263053,
    "description":"",
   
"location":"",
    "link":"http:\/\/www.facebook.com\/album.php?aid=728&id=14762",
    "size":3,
    "type":"normal",
    "object_id":16}

]

What I'm trying to do is iterate through these items. 

I've tried

 IEnumerator > enum1 = myJObject.GetEnumerator();
while(enum1.MoveNext())
{
                    Response.Write("The key is: " + enum1.Current.Key + ", Value is: " + enum1.Current.Value + "");
}

AND

foreach(KeyValuePair kvp in myJObject)
                {
                    Response.Write("The key is: " + kvp.Key + ", Value is: " + kvp.Value + "");
                }

 These both wriout out the keys and values of the first JToken containing name="Profile Pictures" - how can I get to the 2nd JToken and iterate it's key/value pairs?

 

Thanks in advance!

 

 

Coordinator
Jul 19, 2010 at 11:59 PM
Edited Jul 20, 2010 at 12:00 AM

Your JSON is two JObject's in a JArray. Just get the second JObject out of the JArray like you would a normal .NET array: by its index.

Jul 20, 2010 at 2:51 AM

Thank you.  Using JArray instead of JObject worked great!