I'm utilizing the USDA's food database, and have gotten my web application to properly return their JSON through an HTTPRequest. However, I've never seen JSON data this complex before, and am wondering how I should go about getting individual properties?
I noticed that they separated nutrients into an array, so I'd like to see if I can do this without parsing the JSON as a string. (the majority of the solutions I've seen on SO offer this solution.) I'm using AngularJS, though a syntactical answer is all I require.
Here is some of the JSON (I cut some out to save space):
{
"report": {
"sr": "27",
"type": "Basic",
"food": {
"ndbno": "01003",
"name": "Butter oil, anhydrous",
"nutrients": [
{
"nutrient_id": "255",
"name": "Water",
"group": "Proximates",
"unit": "g",
"value": "0.24",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.03"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.49"
}
]
},
{
"nutrient_id": "208",
"name": "Energy",
"group": "Proximates",
"unit": "kcal",
"value": "876",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "112"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "1796"
}
]
},
{
"nutrient_id": "268",
"name": "Energy",
"group": "Proximates",
"unit": "kJ",
"value": "3664",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "469"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "7511"
}
]
},
{
"nutrient_id": "203",
"name": "Protein",
"group": "Proximates",
"unit": "g",
"value": "0.28",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.04"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.57"
}
]
},
{
"nutrient_id": "204",
"name": "Total lipid (fat)",
"group": "Proximates",
"unit": "g",
"value": "99.48",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "12.73"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "203.93"
}
]
},
{
"nutrient_id": "207",
"name": "Ash",
"group": "Proximates",
"unit": "g",
"value": "0.00",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.00"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.00"
}
]
},
{
"nutrient_id": "205",
"name": "Carbohydrate, by difference",
"group": "Proximates",
"unit": "g",
"value": "0.00",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.00"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.00"
}
]
},
{
"nutrient_id": "291",
"name": "Fiber, total dietary",
"group": "Proximates",
"unit": "g",
"value": "0.0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.0"
}
]
},
{
"nutrient_id": "269",
"name": "Sugars, total",
"group": "Proximates",
"unit": "g",
"value": "0.00",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.00"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.00"
}
]
},
{
"nutrient_id": "301",
"name": "Calcium, Ca",
"group": "Minerals",
"unit": "mg",
"value": "4",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "1"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "8"
}
]
},
{
"nutrient_id": "303",
"name": "Iron, Fe",
"group": "Minerals",
"unit": "mg",
"value": "0.00",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.00"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.00"
}
]
},
{
"nutrient_id": "304",
"name": "Magnesium, Mg",
"group": "Minerals",
"unit": "mg",
"value": "0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0"
}
]
},
{
"nutrient_id": "305",
"name": "Phosphorus, P",
"group": "Minerals",
"unit": "mg",
"value": "3",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "6"
}
]
},
{
"nutrient_id": "306",
"name": "Potassium, K",
"group": "Minerals",
"unit": "mg",
"value": "5",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "1"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "10"
}
]
},
{
"nutrient_id": "307",
"name": "Sodium, Na",
"group": "Minerals",
"unit": "mg",
"value": "2",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "4"
}
]
},
{
"nutrient_id": "309",
"name": "Zinc, Zn",
"group": "Minerals",
"unit": "mg",
"value": "0.01",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.00"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.02"
}
]
},
{
"nutrient_id": "312",
"name": "Copper, Cu",
"group": "Minerals",
"unit": "mg",
"value": "0.001",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.000"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.002"
}
]
},
{
"nutrient_id": "315",
"name": "Manganese, Mn",
"group": "Minerals",
"unit": "mg",
"value": "0.000",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.000"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.000"
}
]
},
{
"nutrient_id": "317",
"name": "Selenium, Se",
"group": "Minerals",
"unit": "\u00B5g",
"value": "0.0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.0"
}
]
},
{
"nutrient_id": "401",
"name": "Vitamin C, total ascorbic acid",
"group": "Vitamins",
"unit": "mg",
"value": "0.0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.0"
}
]
},
{
"nutrient_id": "404",
"name": "Thiamin",
"group": "Vitamins",
"unit": "mg",
"value": "0.001",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.000"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.002"
}
]
},
{
"nutrient_id": "405",
"name": "Riboflavin",
"group": "Vitamins",
"unit": "mg",
"value": "0.005",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.001"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.010"
}
]
},
{
"nutrient_id": "406",
"name": "Niacin",
"group": "Vitamins",
"unit": "mg",
"value": "0.003",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.000"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.006"
}
]
},
{
"nutrient_id": "410",
"name": "Pantothenic acid",
"group": "Vitamins",
"unit": "mg",
"value": "0.010",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.001"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.020"
}
]
},
{
"nutrient_id": "415",
"name": "Vitamin B-6",
"group": "Vitamins",
"unit": "mg",
"value": "0.001",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0.000"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0.002"
}
]
},
{
"nutrient_id": "417",
"name": "Folate, total",
"group": "Vitamins",
"unit": "\u00B5g",
"value": "0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0"
}
]
},
{
"nutrient_id": "431",
"name": "Folic acid",
"group": "Vitamins",
"unit": "\u00B5g",
"value": "0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0"
}
]
},
{
"nutrient_id": "432",
"name": "Folate, food",
"group": "Vitamins",
"unit": "\u00B5g",
"value": "0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0"
}
]
},
{
"nutrient_id": "435",
"name": "Folate, DFE",
"group": "Vitamins",
"unit": "\u00B5g",
"value": "0",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "0"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "0"
}
]
},
{
"nutrient_id": "421",
"name": "Choline, total",
"group": "Vitamins",
"unit": "mg",
"value": "22.3",
"measures": [
{
"label": "tbsp",
"eqv": 12.8,
"qty": 1.0,
"value": "2.9"
},
{
"label": "cup",
"eqv": 205.0,
"qty": 1.0,
"value": "45.7"
}
]
},
Aucun commentaire:
Enregistrer un commentaire