Get specific value from a JSON URL in JAVA

0

Good morning Friends.

I'm having a hard time dealing with information collected in a third-party JSON url online, my JPA needs information from multiple sites that return in different ways in the JSON queries, below I'll outline the ways they return and which ones I can handle.

Return example 1

{"alface": "12.23", "pepino": "12.43","batata": "12.49"}

I can capture and treat it any way I want.

Return example 2.

{"quitanda 1": {"alface": "12.23", "pepino": "12.43"}}

I can capture and treat it any way I want.

Return example 3 (I can not get any value)

[{"id":"alface","name": "ALFACE","symbol": "AF",},{"id": "pepino","name": "PEPINO","symbol": "PE",},{"id": "batata","name": "BATATA","symbol": "BA",}]

In this third type return from the third-party URL JSON I can not do anything, when entering the bracket [] I can not get values nor navigate inside the return in any way, could someone send me an example code capturing and printing on screen, any value of the third return mode can be either in JSON or GSON.

I'm doing my JAVA APP on ECLIPSE, it's not an app for a grocery store I just put the same stuff in return to get clearer.

    
asked by anonymous 12.03.2018 / 14:59

1 answer

0

You can turn json's return into a map, then search by key and value

For example:

HashMap<String,Object> result =
    new ObjectMapper().readValue(JSON_SOURCE, HashMap.class);
    
12.03.2018 / 15:10