I'm pretty new to JAVA so my apologies for asking a rather elementary question.
I have a json string that looks like this.
{"statusCode":201,
"body":"[[\"food_corn\",\"48\"],[\"food_potatoes\",\"130\"],[\"food_rice\",\"80\"]]",
"headers":{"Access-Control-Allow-Origin":"*"}}
I'm only interested in the body of the text which may have any number of elements.
At the end I'd like to have a map
with the item name as the key and the number as the correspond value (as an integer).
Thanks for the help!
Update on where I'm at
String decoded = new String(invoke.getPayload().array(), "UTF-8");
HashMap<String, Object> map = new ObjectMapper().readValue(decoded, HashMap.class);
Object body = map.get("body")
where body looks like this
[["food_corn","48"],["food_potatoes","130"],["food_rice","80"],["food_wheat","999"]]
So then I try parsing it into an array like so
JSONArray array = new JSONArray(body);
But I get the error
EXCEPTION: JSONArray initial value should be a string or collection or array.
Which doesn't make sensee to me because the above looks like an array of arrays, no?