Return JSON Giving Error

0

I'm doing a service to get the JSON return in an Android application, so far so good, but I do not know where I'm wrong at the time of getting the value.

The structure of JSON is this:

"entity": {
    "code": 1,
    "message": "Sucesso",
    "clienteModel": {
        "codigoCliente": 1,
        "nomeCliente": "ederson",
        "rgCliente": "448868",
        "cpfCliente": "11212444488",
        "dataNascimentoCliente": 614833200000,
        "emailCliente": "eder",
        "dataCadastroCliente": 1504666800000,
        "codigoEndereco": {
            "code": 1,
            "message": "Sucesso",
            "codigoEndereco": 1,
            "nomeEndereco": "teste",
            "complementoEndereco": "sxasdf",
            "estadoEndereco": "sdafasd",
            "cidadeEndereco": "sdfasd",
            "bairroEndereco": "sdasds",
            "numeroEndereco": 11211,
            "numeroCEPEndereco": "06851020"
        }
    }
},

This is my method where I read JSON, when I try to get the client code it does not find, what am I doing wrong? the code and the message I can get from the other fields can not catch.

private ClienteSaidaDTO getClienteSaidaDTOs(String jsonString) {

    ClienteSaidaDTO trends = new ClienteSaidaDTO();

    try {
        JSONObject jsonObjectConvertString = new JSONObject(jsonString);
        JSONObject jsonObjectEntity = jsonObjectConvertString.getJSONObject("entity");
        //JSONObject jsonObjectClienteModel = jsonObjectConvertString.getJSONObject("clienteModel");

        ClienteSaidaDTO clienteSaidaDTO = new ClienteSaidaDTO();
        ClienteModel clienteModel = new ClienteModel();

        clienteSaidaDTO.setCode(jsonObjectEntity.getInt("code"));
        clienteSaidaDTO.setMessage(jsonObjectEntity.getString("message"));

        clienteModel.setCodigoCliente(jsonObjectEntity.getInt("codigoCliente"));

        clienteSaidaDTO.setClienteModel(clienteModel);

        trends = clienteSaidaDTO;
        //}
    } catch (JSONException e) {
        Log.e("DEVMEDIA", "Erro no parsing do JSON", e);
    }

    return trends;
}
    
asked by anonymous 18.09.2017 / 00:13

1 answer

0

It is because the "CustomerCode" is inside the "clientModel" array, so you should first get the "clientModel" array.

String[] clienteModel = jsonObjectEntity.getStringArray("clienteModel");
    
18.09.2017 / 13:45