Help parsing and reading a BEA JSON file with jQuery getJSON

I am trying to access data from the BEA using their API.

The URL requires a key, but here it is with the key left out

http://www.bea.gov/api/data/?&UserID=MYKEY&method=GETDATA&datasetname=RegionalData&KeyCode=PCPI_CI&GeoFIPS=19001,19003,19005,19007,19009&Year=2012&ResultFormat=json&jsonp=cjs

The result is

cjs({"BEAAPI":{"Request":{"RequestParam":[{"ParameterName":"RESULTFORMAT","ParameterValue":"JSON"},{"ParameterName":"YEAR","ParameterValue":"2012"},{"ParameterName":"USERID","ParameterValue":"005E537D-F683-457E-A70B-128195319CE1"},{"ParameterName":"JSONP","ParameterValue":"CJS"},{"ParameterName":"GEOFIPS","ParameterValue":"19001,19003,19005,19007,19009"},{"ParameterName":"KEYCODE","ParameterValue":"PCPI_CI"},{"ParameterName":"DATASETNAME","ParameterValue":"REGIONALDATA"},{"ParameterName":"METHOD","ParameterValue":"GETDATA"}]},"Results": {"Statistic":"Per capita personal income","UnitOfMeasure":"dollars","PublicTable":"CA1-3 Personal income summary","UTCProductionTime":"2014-10-13T21:46:25.680","NoteRef":"2" ,"Dimensions": [{"Ordinal":"1","Name":"GeoFips","DataType":"string","IsValue":"0"},{"Ordinal":"2","Name":"GeoName","DataType":"string","IsValue":"0"},{"Ordinal":"3","Name":"Code","DataType":"string","IsValue":"0"},{"Ordinal":"4","Name":"TimePeriod","DataType":"string","IsValue":"0"},{"Ordinal":"5","Name":"CL_UNIT","DataType":"string","IsValue":"0"},{"Ordinal":"6","Name":"UNIT_MULT","DataType":"numeric","IsValue":"0"},{"Ordinal":"7","Name":"DataValue","DataType":"numeric","IsValue":"1"}],"Data": [{"GeoFips":"19001","GeoName":"Adair, IA ","Code":"PCPI_CI","TimePeriod":"2012","CL_UNIT":"USD","UNIT_MULT":"0","DataValue":"40008"},{"GeoFips":"19003","GeoName":"Adams, IA ","Code":"PCPI_CI","TimePeriod":"2012","CL_UNIT":"USD","UNIT_MULT":"0","DataValue":"53297"},{"GeoFips":"19005","GeoName":"Allamakee, IA ","Code":"PCPI_CI","TimePeriod":"2012","CL_UNIT":"USD","UNIT_MULT":"0","DataValue":"37269"},{"GeoFips":"19007","GeoName":"Appanoose, IA ","Code":"PCPI_CI","TimePeriod":"2012","CL_UNIT":"USD","UNIT_MULT":"0","DataValue":"31384"},{"GeoFips":"19009","GeoName":"Audubon, IA ","Code":"PCPI_CI","TimePeriod":"2012","CL_UNIT":"USD","UNIT_MULT":"0","DataValue":"50094"}],"Notes": [{"NoteRef":"2","NoteText":"Per capita personal income was computed using Census Bureau midyear population estimates. Estimates for 2010-2012 reflect county population estimates available as of March 2013."},{"NoteRef":"Note--","NoteText":"All dollar estimates are in current dollars (not adjusted for inflation)."},{"NoteRef":" ","NoteText":"Last updated: May 30, 2014-- revised estimates for 1969-2000."}]}}})


How would I access it so I could print to the console the data value for Adams, IA  - which would be 53297  - note printing all to console is fine - filtering is not part of this question.

So basically I am just not sure how to access it with jQuery getJSON
lvmllcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
test page : http://jsfiddle.net/3a18jkrn/

function cjs(json) {
    var data = json.BEAAPI.Results.Data;
    for(var i=0;i<data.length;i++) {
        if(data[i].GeoName == "Adams, IA ") { // be careful you've an extra space !!!
//            console.log(data[i].DataValue);
            alert(data[i].DataValue);
        }
    }
}

Open in new window

0
lvmllcAuthor Commented:
I see how this works with the result when on the same page, but I still have an issue with how I retrieve it using the URL
 
http://www.bea.gov/api/data/?&UserID=MYKEY&method=GETDATA&datasetname=RegionalData&KeyCode=PCPI_CI&GeoFIPS=19001,19003,19005,19007,19009&Year=2012&ResultFormat=json&jsonp=cjs
0
leakim971PluritechnicianCommented:
You must have a cjs function?
0
Albert Van HalenAnalyst developerCommented:
Define your callback method (in your case 'cjs') in your page. After that you can retrieve the data by using $.ajax and set the dataType to jsonp. getJSON won't work because of CORS is disabled by default.

Take a look here : http://jsfiddle.net/qb12j9e8/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.