JSON Polyline Graphic

Discussion created by glenjansma on Apr 11, 2010
Latest reply on Apr 12, 2010 by psitton
I am trying to use the JSON objects.  I have small program which creates a polyline graphic.  I seem to create the object correctly (by viewing the alerts in the code) but the result is no graphic on the map.  Also there is no error message.  I was using the list of coordinates method and it works, but I would like to use JSON if possible.

Here is a portion of the code:
// start with array of coordinates (various lengths...)
// for each offset to x0,y0 and resize dx,dy

var myJSON = "jsnpolyline = {\"paths\":[[";                   // beginning of json string

ncoord = arrayofcoord.length;

for(j=0; j<ncoord; j+=2)
    ln0 = x0 + (arrayofcoord[j])*dx;                           // first in pair
    lt0 = y0 + (arrayofcoord[j+1])*dy;                        // second in pair
  if(j>0) myJSON = myJSON + ", ";                     //add comma between pairs --- after first pair
  myJSON = myJSON + "["+ln0+","+lt0+"]";         // add next pair to json string

myJSON = myJSON + "]],\"spatialReference\":{\"wkid\":4152}}";          // add this to end of jason string

alert(myJSON);  // for debugging (see below)


alert(jsnpolyline.paths); // for debugging(see below)

var polyline = new esri.geometry.Polyline(jsnpolyline);

var graphic = new esri.Graphic(polyline, numsymbol);


the first alert above produces something similar to:
jsnpolyline = {"paths":[[[-117.946655,33.641689],[-117.94346,33.645121]]],"spatialReference":{"wkid":4152}}
(note this is a shortened sample ... the arrays have between 4 and 18 point pairs)

the second alert produces similar to (same note as above):

Thanks, Glen