Get object properties value in javascript obtained via json from Controller as Hashtable

I read here a few topics on how to get property values ​​from an object.

In my case, I have something in the controller:

[HttpPost]
public ActionResult GetSomething() {

return Json( new {
     data = AModel.Get()
     }, JsonRequestBehavior.AllowGet );

}

In the model:

public static List<Hashtable> Get() {
    List<Hashtable> list = new List<Hashtable>( 0 );
    Hashtable table = new Hashtable();
    table.Add( "ITEM_1", "Value1" );
    table.Add( "ITEM_2", "Value 32" );
    list.Add( table );

    table = new Hashtable();
    table.Add( "ITEM_1", "Value22" );
    table.Add( "ITEM_2", "Other" );
    list.Add( table );

   return list;
}

And in Javascript:

var test;
 $.ajax({
    type: "post",
    url: "Action/Controller",
    data: {},
    dataType: "json",
    async: false,
    success: function (data) {
            test = data.data;
         },
    complete: function () {
            console.log(test);              
 });

I got the console, as in the following image:

enter image description here

I want to get the property value ITEM_1and the results for me: Value1, Value22.

I tried using

for(var key in test) {
console.log(test[key].ITEM_1);
//console.log(test[key].ITEM1);
}

but it does not work.

Of course, I renamed the key ITEM_1to ITEM1(in the model), but the same result: undefinedbut in the console I see the values ​​for the whole object.

enter image description here

Help me please.

+3
source share
1 answer

testis an array, not an object. loop through an array, for example:

var testLength = test.length;            //caching length, performance benefit
    i, item1;

for(i=0;i<testLength;i++){
    item1 = test[i].Properties.ITEM1;
}
+3
source

All Articles