This project has moved and is read-only. For the latest updates, please go here.

Iterating JObject

Jul 19, 2010 at 11: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 20, 2010 at 12:59 AM
Edited Jul 20, 2010 at 1: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 3:51 AM

Thank you.  Using JArray instead of JObject worked great!