Keith McElroy
asked on
JSON extract data
JSON data parse
How can make the following code extract the numeric value from the "meals" element
Need the numeric value from this: "meals":55. which is contained in the return json from the following getJSON
code:
$.getJSON("https://api.gsa.gov/travel/perdiem/v2/rates/city/Richland/state/WA/year/2019?api_key=8DYKMOjODhqMfQLD3t4xFsXVeav1LkIPX5aOihPK", function (data) {
var items = [];
$.each( data, function( key, val ) {
//items.push( "<li id='" + key + "'>" + val + "</li>" );
//alert(key + " "+ val);
});
sample return json (see meals:55 below:
{"request":null,"errors":n ull,"rates ":[{"oconu sInfo":nul l,"rate":[ {"months": {"month":[ {"value":9 4,"number" :1,"short" :"Jan","lo ng":"Janua ry"},{"val ue":94,"nu mber":2,"s hort":"Feb ","long":" February"} ,{"value": 94,"number ":3,"short ":"Mar","l ong":"Marc h"},{"valu e":94,"num ber":4,"sh ort":"Apr" ,"long":"A pril"},{"v alue":94," number":5, "short":"M ay","long" :"May"},{" value":94, "number":6 ,"short":" Jun","long ":"June"}, {"value":9 4,"number" :7,"short" :"Jul","lo ng":"July" },{"value" :94,"numbe r":8,"shor t":"Aug"," long":"Aug ust"},{"va lue":94,"n umber":9," short":"Se p","long": "September "},{"value ":94,"numb er":10,"sh ort":"Oct" ,"long":"O ctober"},{ "value":94 ,"number": 11,"short" :"Nov","lo ng":"Novem ber"},{"va lue":94,"n umber":12, "short":"D ec","long" :"December "}]},]"mea ls":55,"zi p":null,"c ounty":"", "city":"St andard Rate","standardRate":"fals e"}],"stat e":"CA","y ear":2019, "isOconus" :"false"}] ,"version" :null}
How can make the following code extract the numeric value from the "meals" element
Need the numeric value from this: "meals":55. which is contained in the return json from the following getJSON
code:
$.getJSON("https://api.gsa.gov/travel/perdiem/v2/rates/city/Richland/state/WA/year/2019?api_key=8DYKMOjODhqMfQLD3t4xFsXVeav1LkIPX5aOihPK", function (data) {
var items = [];
$.each( data, function( key, val ) {
//items.push( "<li id='" + key + "'>" + val + "</li>" );
//alert(key + " "+ val);
});
sample return json (see meals:55 below:
{"request":null,"errors":n
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked directly and really helps me move forward learning, using json.
I truly appreciate your expertise on this.
I truly appreciate your expertise on this.
You are welcome!
Here is one from the link in the post
https://jsfiddle.net/mplungjan/97tvy85o/
Open in new window