So I can get two possible outputs out of an API, I can choose what i want, the thing is i need to parse it in my java code and get the Value at the gm tag, or throw an Exception if there is no gm tag, and get one value out of it, the librarys I'm using are: org.json,org.apache.commons.configuration, i can use what i want as long as it can be injected with Maven. Throwing the Exception etc. is simple, accessing the value on the other hand gets me, if there is no simple solution i'll just write a while loop that is searching for the tag
The XML-String looks like this:
<report sr="28" groups="All groups" subset="All foods" end="0" start="0" total="0">
<foods>
<food ndbno="45149194" name="AHOLD, DIET GINGER BEER, UPC: 688267176883" weight="355.0" measure="1.0 BOTTLE">
<nutrients>
<nutrient nutrient_id="208" nutrient="Energy" unit="kcal" value="0" gm="0.0"/>
</nutrients>
</food>
</foods>
</report>
The JSON-String looks like this:
{
"report": {
"sr": "28",
"groups": "All groups",
"subset": "All foods",
"end": 0,
"start": 0,
"total": 0,
"foods": [
{
"ndbno": "45149194",
"name": "AHOLD, DIET GINGER BEER, UPC: 688267176883",
"weight": 355.0,
"measure": "1.0 BOTTLE",
"nutrients": [
{
"nutrient_id": "208",
"nutrient": "Energy",
"unit": "kcal",
"value": "0",
"gm": 0.0
}
]
}
]
}
}
I will use whatever is more simple,I would also be happy if some1 can point out an alternativ library because org.json seems overly complicated.
I just can't wrap my head around it, i need to access the "gm" value, or throw an Exception if there is no such value.