Alright, I'm not sure if I'm asking the right question, but here goes. I'm using Javascript .NET to parse a Javascript object array. My code looks something like this:
object packlist;
using (var context = new JavascriptContext())
{
context.Run(@"function packlist() { this.packs = new Array(); }
var packlist = new packlist();
packlist.packs[0] = { item1:""something"", item2:""something2"", item3:""something3"" };
packlist.packs[1] = { item1:""something"", item2:""something2"", item3:""something3"" };
packlist.packs[2] = { item1:""something"", item2:""something2"", item3:""something3"" };");
packlist = context.GetParameter("packlist");
}
While debugging, the Locals window says the object looks like this
My question would be how would I go about accessing item1
from packlist.packs[0]
?
The general structure is as follow:
Meaning it is a dictionary where each value is an arry of dictionaries.
Should be
Or
The difference between them is that in the first, it is assumed that the key exists in the dictionary otherwise it throws an exception. In the second, it will try to get the value and tell you if the key is valid.
To check if a key is in the dictionary you can use this:
To run through all the items in the dictionary
Here's the MSDN link for the dictionary class
http://msdn.microsoft.com/fr-fr/library/bb347013.aspx
I think it is:
var a = packlist.packs[0]["item1"];
Your packlist variable is a Dictionary with a single key, with the value being a object-array and every entry in that array also is a Dictionary. So getting the value would go something like this.