Link to home
Start Free TrialLog in
Avatar of trevor1940
trevor1940

asked on

jQuery: Looping through some JSON data

Hi
I'm trying to loop through some JSON data on a closed system so I can't upload a sample
Could someone give me a clue where to start?

                $.ajax( {
                                url : link,
                                type : 'get',
                                datatype: json,
                                success : function( resp ) {
                                                console.dir(resp);
                                                var elm;
                                                $.each(resp.features, function(key, value){
                                                                elm.append('<tr />');
                                                                $.each(value.attributes, function(key, value){
                                                                                elm.append('<td>' + key.name + ‘</td>’ …);
                                                                });
                                                });
                                                elm.appendTo('#Results');

                                }
                });

Open in new window


CONSOLE output
displayFieldName: "SORT_NAME"
features:Array[1000]
                0:Object
                attributes:Object
           NAME: "My place"
           LONG_: 123
           LAT: 56
...........
   length: 1000
fieldAliases: Object
      NAME: NAME
      LONG_: LONG
      LAT:LAT

Open in new window

Avatar of Rikin Shah
Rikin Shah
Flag of India image

Hi,

I suppose, you get the JSON String from where you're sending the request. You just need to convert it to an object and traverse through it.

var obj = JSON.parse(jsonString);

Open in new window

Avatar of trevor1940
trevor1940

ASKER

Looking at the "Network" tab in Firefox it's already in JSON
Part of the link is "&format=json" so why would I need to parse the jsonString
Isn't success : function( resp ) / resp already a JSON object?
I've found some similar looking data here

I'm interested in the feature attributes although different from the sample the format is the same how might I access these?

{  
   "objectIdFieldName":"objectid",
   "globalIdFieldName":"globalid",
   "geometryType":"esriGeometryPoint",
   "spatialReference":{  
      "wkid":4326,
      "latestWkid":4326
   },
   "fields":[  ],
   "features":[  
      {  
         "attributes":{  
            "objectid":271186,
            "facilityid":"174169002093",
            "facname":"CLIFFORD CRONE MIDDLE SCHOOL",
            "factype":null,
            "organiz":null,
            "jurisdict":"NAPERVILLE",
            "pocname":null,
            "pocemail":null,
            "pocphone":null,
            "capacity":"093",
            "hoursoper":null,
            "daysoper":null,
            "accessres":null,
            "opendate":null,
            "closeddate":null,
            "opsstatus":null,
            "lastupdate":null,
            "lasteditor":null,
            "globalid":"{597AEE1C-5E32-42BE-9E4C-4A2A0F6D5F8F}",
            "sheltstat":1,
            "sheltcap":93,
            "sheltcurpop":46,
            "petfriend":0,
            "wheelchair":0,
            "adacomp":0
         },

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of trevor1940
trevor1940

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial