looking for some solutions? You are welcome.

SOLVED: Using local json file to lookup key:value using javascript

user3294636:

I have a state-abbreviation json file from here. In my .js file, I have var=state that I want to look up the abbreviation for. So I need help in finding how to do that. For example lookup state (=Maine) in the json to get the "ME" value. Please help! Newbie in javascript so please please be as basic as possible in your answer. Thanks

Update So my json is fine. Here is a sample from it...

[{"Alabama": "AL","Alaska": "AK","American Samoa": "AS",.....})

In my .js file, I am 'trying' to get the json file and use it for lookup like so. Obviously this isn't working. I know there are many mistakes so please be nice when helping out. Remember I am a newbie. ;-)

$.getJSON("/files/json/states_hash.json", function(json){
var data = eval("(" + json.responseText +")");
var val=_.findValue(json, stateNameVar);
console.log(json);
});



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE
Share:

No comments:

Recent