Select to view content in your preferred language

Access Attribute

890
4
09-09-2011 08:51 AM
BrianGustafson
Occasional Contributor
I am doing an Identify task and the results come back fine.  I want to get a single value out of the returned results.  How would I do that?

var segResult = idResult.Graphic;
alert(segResult.attributes[0]);
0 Kudos
4 Replies
JeffPace
MVP Alum
I am doing an Identify task and the results come back fine.  I want to get a single value out of the returned results.  How would I do that?

var segResult = idResult.Graphic;
alert(segResult.attributes[0]);


attributes are a json object.

so if you know the field name, you can do

alert(segResult.attributes["FIELD_NAME"]);
0 Kudos
BrianGustafson
Occasional Contributor
That got me on the right track, I also needed to change the property Graphic to feature.  However,  when I get my result it always says undefined.  Is there away to see the raw json returned besides fiddler?  I am using Visual Studio.
0 Kudos
JeffPace
MVP Alum
That got me on the right track, I also needed to change the property Graphic to feature.  However,  when I get my result it always says undefined.  Is there away to see the raw json returned besides fiddler?  I am using Visual Studio.


I dont use VS, i just use Mozilla and you can alert toSource()

however,
An identify should return a FeatureSet. 

so you can do

//featureSet.features returns a Graphics Array

dojo.forEach(featureSet.features, dojo.hitch(this, function(feature){
//each feature is a graphic
//feature.attributes is the json object
alert(feature.attributes["Field_NAME"]);
}));
0 Kudos
derekswingley1
Deactivated User
Is there away to see the raw json returned besides fiddler?


You can tweak the URL sent to your service and see the JSON directly in the browser. For instance, the basic identify sample, when you click the map, issues a request like this:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer...{%22x%22%3A-9270185.452645523%2C%22y%22%3A5247230.008462553%2C%22spatialReference%22%3A{%22wkid%22%3A102100}}&tolerance=3&returnGeometry=true&mapExtent={%22xmin%22%3A-9270630.93720096%2C%22ymin%22%3A5246864.543921095%2C%22xmax%22%3A-9269675.474347476%2C%22ymax%22%3A5247581.141061208%2C%22spatialReference%22%3A{%22wkid%22%3A102100}}&imageDisplay=800%2C600%2C96&geometryType=esriGeometryPoint&sr=102100&layers=all%3A0%2C2&callback=dojo.io.script.jsonp_dojoIoScript3._jsonpCallback

If you change the f query string parameter to pjson and remove the callback stuff, you get this:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer...{%22x%22%3A-9270185.452645523%2C%22y%22%3A5247230.008462553%2C%22spatialReference%22%3A{%22wkid%22%3A102100}}&tolerance=3&returnGeometry=true&mapExtent={%22xmin%22%3A-9270630.93720096%2C%22ymin%22%3A5246864.543921095%2C%22xmax%22%3A-9269675.474347476%2C%22ymax%22%3A5247581.141061208%2C%22spatialReference%22%3A{%22wkid%22%3A102100}}&imageDisplay=800%2C600%2C96&geometryType=esriGeometryPoint&sr=102100&layers=all%3A0%2C2
0 Kudos