Iterating JObject

Jul 19, 2010 at 10:30 PM

Here is my JSON:

   "name":"Profile Pictures",

    "name":"Family Pictures",


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

I've tried

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


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!



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!