Click here to Skip to main content
15,888,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web application,based on MVC, where the object "myMap" is a Map<integer,object> that i populate into Controller and i pass to the View. How can i parse it?
When i run application, i can see this in the view:
C#
<pre lang="Javascript">
var myMap ={0:{'cellId':'15064','creationTime':null,'date':'20120528','direction':'O','id':null,'localAreaCode':'20016','modificationTime':null,'receiver':'URkatij09Kce/Qj0vnEr8s','sender':'VdzW4Vvb7IcjURYCGBs.Is','siteName':'NAVIGLIO PAVESE','time':'222932','version':0},
1:{'cellId':'15064','creationTime':null,'date':'20120528','direction':'O','id':null,'localAreaCode':'20016','modificationTime':null,'receiver':'URkatij09Kce/Qj0vnEr8s','sender':'VdzW4Vvb7IcjURYCGBs.Is','siteName':'CERMENATE','time':'222932','version':0}};
</pre>

How can i get values associated to a key? (for example SiteName value for every key) Thank you

What I have tried:

CSS
for (var m in myMap){
      for (var i=0;i<myMap[m].length;i++){

   geocoder.geocode({'address': myMap[m][i]}, function(results, status) {
     if (status === 'OK') {
           resultsMap.setCenter(results[0].geometry.location);
           var marker = new google.maps.Marker({
            map: resultsMap,
            position: results[0].geometry.location
           });

     } else {
       alert('Geocode was not successful for the following reason: ' + status);
     }
   });
   }
 }
Posted
Updated 31-Jan-17 6:07am
Comments
Did you debug?
Karthik_Mahalingam 9-Nov-16 23:21pm    
issue in json object or map?

1 solution

myMap[m]
Is not an array as far as I can tell.
So this;
for (var i=0;i<myMap[m].length;i++){

Won't work.
Write the word debugger; in you're code inside first loop.
It will change you're world.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900