Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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+')');

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

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.

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;
share|improve this answer
Devdatta Tengshe- Thank you .. Its working – Arun Jul 1 '13 at 7:15

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