JSON data From Census

Posted on 2013-11-01
Last Modified: 2013-11-02
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,NAME&for=state:19,38

["672591","North Dakota","38"]],NAME&for=state:19,38&jsonp=cjs

["672591","North Dakota","38"]])

In the case of the first URL I have the following code


Open in new window

The alert produces a string
P0010001,NAME,state,3046355,Iowa,19,672591,North 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.
Question by:lvmllc
  • 2
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39617898
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

Author Comment

ID: 39618207
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?
LVL 52

Accepted Solution

Scott Fell,  EE MVE earned 250 total points
ID: 39618238
If your "get" or "post" returns 1 or 10,000 records, they all would show up when you try and output "data".     From there, you would not typically use "data" to display your the output unless for instance the data being returned was not json and instead a short bit of text or  html.  If you do have 10,000 rows of data in json/jsonp it is all on the client machine and you can now access the data many multiple times by calling just the portion of data you need without making more trips to the server.  

10,000 rows of data is more than likely going to be too much and there would be a long initial lag time for all that data to load.   Let's say you do have 10,000 total rows of data, you would probably want to make your ajax call return just several hundred rows at a time.  Then on your actual web page, you may display just 10 rows of data at a time.  You would set up some type of paging that tracks where the user is and at the appropriate spot, call additional data to load similar to this example
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 100 total points
ID: 39618803
My first question is why does Alert make a string and not display object object?

Because your returned data is an array - not an object!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question