1
[  
   {  
      "MAP_COORDINATES":
          "[[32.732695279933104,74.86289978027344],
            [32.72749665793957,74.85431671142578],
            [32.72143121579454,74.85963821411133],
            [32.72200889472774,74.88521575927734]]"
   }
]

how to parse this array. Please help

1
  • post what you have tried so far Commented Jun 29, 2016 at 5:25

4 Answers 4

1

Changing your code from JSON.parse(polyLocation).forEach(function(v) { ... to JSON.parse(polyLocation[0].MAP_COORDINATES).forEach(function(v) { ... should resolve this issue. Check Fiddle.

Sign up to request clarification or add additional context in comments.

3 Comments

i tried this but control is not going inside the loop. Any suggestion
Its working for me. Check the Fiddle link in the answer. If you are getting any error in browser console, then please provide details.
Hi Hector Thanks for your help . Im getting following error on console Uncaught SyntaxError: Unexpected token u in JSON at position 0. Please help.
1
Use 

var cordData = JSON.parse(polyLocation);
cordData =cordData['MAP_COORDINATES'];

cordData.forEach(function(v) {

     alert(v[0]);
     path.push(new google.maps.LatLng(v[0],v[1]));
     alert("coords main ="+path[0]);


    })

4 Comments

Hi Piyush control is not going inside the loop. Any suggestion... Thanks
Check now can u make sure json.parse is not giving error in consol
Hi Piyush, Thanks for your help . Im getting following error on console Uncaught SyntaxError: Unexpected token u in JSON at position 0. Please help.
Your json was not stringified properly "[{"MAP_COORDINATES":[[32.732695279933104,74.86289978027344],[32.72749665793957,74.85431671142578],[32.72143121579454,74.85963821411133],[32.72200889472774,74.88521575927734]]}]" This should be the correct input
0

Try this

var a ='[{"MAP_COORDINATES":"[[32.732695279933104,74.86289978027344],[32.72749665793957,74.85431671142578],[32.72143121579454,74.85963821411133],[32.72200889472774,74.88521575927734]]"}]' ;
var b =JSON.parse(a);
var data = JSON.parse(b[0].MAP_COORDINATES);
data.forEach(function(v) {
          console.log(v);
 })

Comments

0

You need to change your json syntax..

var app=[ 
   {  
      "MAP_COORDINATES":{
          ["32.732695279933104,74.86289978027344",
            "32.72749665793957,74.85431671142578",
            "32.72143121579454,74.85963821411133",
            "32.72200889472774,74.88521575927734",
   ]}}
];

app[0].MAP_COORDINATES[0]

"32.732695279933104,74.86289978027344"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.