How to handle json in java

1

I'm trying to handle the following json:

[{"code":"ARS","codein":"BRL","name":"Peso Argentino (R$)","high":"0.165","low":"0.1638","pctChange":"0.182","open":"0","bid":"0.1643","ask":"0.1647","varBid":"0.0003","timestamp":"1522699200000","create_date":"2018-04-02 20:20:08"}]

I'm using:

JSONObject json = new JSONObject(responseBody);
            JSONArray dados = json.getJSONArray("NÃO EXISTE UMA KEY?");
                for (int i = 0; i < dados.length(); ++i) {
                JSONObject linha = dados.getJSONObject(i);
                Log.v("valor", linha.getString("high"));
            }

How do I do when there is no key?

    
asked by anonymous 03.04.2018 / 02:42

1 answer

3
  

Thanks @RBZ I had not tried it, it worked here. - Emerson   Barcellos

Answer:

JSONArray dados = json.getJSONArray(seu_json);

I learned a golden rule, basically like this:

[ = JSONArray

{ = JSONObject

    
03.04.2018 / 13:36