lvmllc
asked on
JSON data From Census
I am working with the US Census API and am curious if I am doing this right or if there is a better way to do this.
I am using CORS but could do this with jsonp
The urls and output are
http://api.census.gov/data/2010/sf1?key=...&get=P0010001,NAME&for=state:19,38
[["P0010001","NAME","state "],
["3046355","Iowa","19"],
["672591","North Dakota","38"]]
http://api.census.gov/data/2010/sf1?key=...&get=P0010001,NAME&for=state:19,38&jsonp=cjs
cjs([["P0010001","NAME","s tate"],
["3046355","Iowa","19"],
["672591","North Dakota","38"]])
In the case of the first URL I have the following code
The alert produces a string
P0010001,NAME,state,304635 5,Iowa,19, 672591,Nor th Dakota,38
and the console prints Iowa
My first question is why does Alert make a string and not display object object?
I think I am OK using this jquery as I am able to access the values, but would like to know if any of you experts have concerns about this method.
I am using CORS but could do this with jsonp
The urls and output are
http://api.census.gov/data/2010/sf1?key=...&get=P0010001,NAME&for=state:19,38
[["P0010001","NAME","state
["3046355","Iowa","19"],
["672591","North Dakota","38"]]
http://api.census.gov/data/2010/sf1?key=...&get=P0010001,NAME&for=state:19,38&jsonp=cjs
cjs([["P0010001","NAME","s
["3046355","Iowa","19"],
["672591","North Dakota","38"]])
In the case of the first URL I have the following code
$.getJSON(url,function(data,status){
alert(data);
console.log(data[1][1])
});
The alert produces a string
P0010001,NAME,state,304635
and the console prints Iowa
My first question is why does Alert make a string and not display object object?
I think I am OK using this jquery as I am able to access the values, but would like to know if any of you experts have concerns about this method.
The reason is your alert is asking for all the data and what you are sending to the console is the 2nd item in the 2nd row of data. Array's are zero based. If you used 0,0 instead, you would have seen, P0010001
ASKER
I understand the 0,0 base. I was just surprised that an alert without specifying the array location returns the full data string.
Any comments on if this is the best approach to grabbing this JSON data?
Any comments on if this is the best approach to grabbing this JSON data?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.