Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My json response:

{"type":"FeatureCollection", "features":[{"type":"Feature","id":"SPATIAL_VIEW.fid-54038ee6_13f98ee9f52_4049","geometry":{"type":"Polygon","coordinates":[[[7.2970943E7,-4.69048595E8]]]},"geometry_name":"GEOM","properties":{"ID":"123","GIS_CODE":"AP","NAME":"Andhra Pradesh"}}],"crs":{"type":"EPSG","properties":{"code":"42106"}}}

In this I want to get the GIS_CODE as an alert.

What I tried is: That json response is in "jsoncontent"

   var content = eval('('+jsoncontent+')');
   alert(content.features.properties.GIS_CODE);

I am getting this error

Uncaught TypeError: Cannot read property 'GIS_CODE' of undefined

How to resolve it?

Any help is greatly appreciated ..

Thank you

share|improve this question
add comment

closed as off-topic by Devdatta Tengshe, iant Jul 1 '13 at 7:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about general computing hardware and software are off-topic here, but can be asked on Super User." – iant
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

There are multiple problems with your code.

  • Firstly you should avoid the usage of eval. It is better to use JSON.parse() to parse JSON Data into objects.
  • Secondly, features is an array. You need to use [] notation to get the object from it.

After that you should be able to access the values. I can use the following code:

var dt=JSON.parse(jsoncontent);
var value=dt.features[0].properties.GIS_CODE;
alert(value);
share|improve this answer
    
Devdatta Tengshe- Thank you .. Its working –  Arun Jul 1 '13 at 7:15
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.