java – How to access the innermost "level" data of a JSON?


I needed a way to be able to access the innermost "level" of JSON below: (name, value, last query and source)

    "status": true,
    "valores": {
        "USD": {
            "nome": "Dólar",
            "valor": 2.333,
            "ultima_consulta": 1386349203,
            "fonte": "UOL Economia -"

I'm trying to access it this way, but it JSONException :

   try {

        String resposta =; //resposta contém o JSON que retorna do WS
        Log.i("RETORNO: -------", resposta);
        JSONObject jo = new JSONObject(resposta);
        JSONArray ja;
        ja = jo.getJSONArray(resposta);
        Log.i("RESULTADO: ", moedas.getAbreviacao());
        Log.i("RESULTADO: ", moedas.getDescricao());
    } catch (IOException e) {
    } catch (JSONException e) {
    } finally {


I even tried using GSON, but I didn't succeed either.


There's no array in the JSON you have – you just have objects (and primitive values ​​- strings, numbers, etc). You'll need to access them as such, something like the code below:

JSONObject jo = new JSONObject(resposta);
JSONObject valores = jo.getJSONObject("valores");
JSONObject usd = valores.getJSONObject("USD");
String nome = usd.getString("nome");
double valor = usd.getDouble("valor");
long ultimaConsulta = usd.getLong("ultima_consulta");
String fone = usd.getString("fone");
Scroll to Top