stevel

How to pass an ArcGIS object via JSON

Discussion created by stevel on Mar 26, 2012
Latest reply on Mar 27, 2012 by ciava.at
The Create Web Map from JSON example shows how to pass parameters from a configuration file to the map:

webmap.itemData ={
          "operationalLayers":[{
            "url":"http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer",
            "visibility":true,
            "opacity":0.75,
            "title":"Soil Survey Map",
            "itemId":"204d94c9b1374de9a21574c9efa31164"
          }]
var layers = response.itemInfo.itemData.operationalLayers;


All of these items are either text, numbers, or boolean. How can I pass an ArcGIS object via JSON? For example, I want to specify a symbol using the same syntax as above. How would I include this symbol in the JSON?

new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
 new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,
 new dojo.Color([255,0,0]), 2),new dojo.Color([255,255,0,0.25]));


If I include this in the JSON without quotation marks, it's marked as an error since the JSON file doesn't know what esri.symbol.SimpleFillSymbol means. If I quote it, ArcGIS doesn't recognise it as an object since it's now a string.

Do I need to break it into the component parts (STYLE_SOLID, STYLE_DASHDOT, [255,0,0], [255,255,0,0.25]) then reassemble?

Thanks for any tips,
Steve

Outcomes