AnsweredAssumed Answered

Javascript array to JSON

Question asked by samirgambhir on Feb 22, 2013
Latest reply on Feb 26, 2013 by samirgambhir
Hi,
I am using ArcGIS Server 10.1 with JavaScript 3.2.
I am running a query on a feature layer and the output is a JavaScript array. I would like the output to be in JSON. I have tried using JSON.stringify(), but the output does not match with the output I get using REST endpoint. Here is my code:
var queryA = new esri.tasks.Query();  queryA.where = myGeogString; //myGeogString declared earlier and has a multiple query string ("State_name"='xyz' OR "State_name"='abc' .....)  queryA.returnGeometry = false;  queryA.outFields = ["*"];  var results;  queryTask.execute(queryA, function(featureSet) {   var attr = [], items = [];   for ( i = 0, il = featureSet.features.length; i < il; i++) {    var features = featureSet.features[i];    var fattributes = features.attributes;    results = [];    for (att in fattributes) {     for ( k = valueB.length; k > -1; k--) { //length of array of indicators for each feature in myGeogString      if (att == valOutB[k]) {       var myInd = valueB[k];       var myAttr = fattributes[att];       results.push(myInd + ":" + myAttr);      }     }    }    items.push("location:"+featureSet.features[i].attributes.State_name + "," + results);   }   var itemsJson = JSON.stringify({locations:items});   alert(itemsJson);  });


Is it possible to convert this output to JSON so it matches with REST output?
Thanks
Samir

Outcomes