In my MVC app, the controller serializes a list of objects using JavaScriptSerializer()
to create a JSON object that is then passed to the client side view.
Oddly enough, when attempting to iterate through the object using a ranged for loop, each object appears as undefined. However, using a regular for loop and indexing the object with the current iteration value in square brackets allows me to access each sub-object successfully (for example, this works:
for(var i = 0; i < jsonObj.length; i++)
compared to this: for(var sub in jsonObj)
). Why does the ranged for loop fail in this scenario?
JSON Object:
[
"Obj1": {
"Value1": "3454234",
"Value2": "345643564",
"Value3": "665445",
"Value4": "True"
},
"Obj2": {
"Value1": "3454234",
"Value2": "345643564",
"Value3": "665445",
"Value4": "True"
},
"Obj3": {
"Value1": "3454234",
"Value2": "345643564",
"Value3": "665445",
"Value4": "True"
}
]
EDIT
for(var sub in finalJson){
console.log(sub["Value1"])
}