0
내 목표 : USDA NDB API에서 추출한 영양 데이터를 표시하는 검색 기능을 구현합니다.API Ajax 구조화
상태 : 부분적인 성공
문제 : USDA 개체가 다소 불쾌한 반환 stuctured. 이 스크린 샷을 참조 하시려면 http://imgur.com/a/gOKdk 피자는 첫 번째 키 값에 물이 있고 우유에는 에너지가 있습니다.
내 질문 :
나는 모든 검색에 대한 예를 들어 에너지를 얻으려면 어떻게 내 아약스 호출을 구성 것인가?
$.ajax({
type: 'GET',
async: false,
url: 'http://api.nal.usda.gov/ndb/reports/?ndbno=' + ndbno[0] + '&type=b&format=json&api_key=',
success: function(results) {
food0 = results.report.food;
console.log(food0);
$("#jsGrid-nutrition").jsGrid("insertItem", {
name: food0.name,
kCal: food0.nutrients[1].measures[0].value,
servingSize: food0.nutrients[1].measures[0].label,
quantity: food0.nutrients[1].measures[0].qty,
carbs: food0.nutrients[4].value + food0.nutrients[4].unit,
fats: food0.nutrients[3].value + food0.nutrients[3].unit,
saturatedFats: food0.nutrients[3].value + food0.nutrients[3].unit,
protein: food0.nutrients[24].value + food0.nutrients[24].unit
});
루프 에너지를 찾아? – epascarello
jquery grep 함수를 사용하여 에너지를 찾을 수 있습니다. http://api.jquery.com/jquery.grep/ – tegon