return function json object

0

I have a function in android that makes the connection to the server and returns me a json, that json is stored in a variable named object.

But I have to make this object go to another screen via return but I'm not getting it.

function

public class dados_ws {

    private static String URL;
    private static String TIPO;
    private static Map PARAMETROS;
    private static String CREDENCIAIS;

    public static JSONObject Dados_Ws(int pagina, String ParametroUrl , Context context) {

        switch (pagina) {
            //Recuperação de senha
            case 1:
                URL = Constantes_WebService.URL_REC_SENHA;
                TIPO = "GET";
                PARAMETROS = null;
                CREDENCIAIS = null + ":" + null;
                break;
        }

        WebService ws = new WebService(
                URL,
                ParametroUrl,
                TIPO,
                PARAMETROS,
                CREDENCIAIS,
                context
        );

        ws.getData(new WebService.RetornoAssincrono()

        {
            @Override
            public JSONObject onSuccess(JSONObject objeto) {
                System.out.println("Sucesso!!! Os valores são: \n" + objeto);

                return objeto;
            }
        });


        return null;
    }

}

return on another page:

 JSONObject dadoslogin = null;
                        dadoslogin = Dados_Ws(1, ParametroUrl , context);
                        try {
                            int status = dadoslogin.getInt("status");
                            final String resultado = dadoslogin.getString("resultado");

                            System.out.println("Status = " + status);
                            System.out.println("Resultado = " + resultado);


                        } catch (JSONException e) {

                            System.out.println("Catch : " + e.getMessage());
                            //hideDialog();
                        }

This code inserted directly on the homepage, returns the data perfectly, but with my error function in the app and says that the variable is null.

    
asked by anonymous 24.01.2018 / 20:15

1 answer

0

A very good library to parse is Gson, it's a google library, link

Example to move from json to object (object named Response):

Gson gson = new Gson();
Response response = gson.fromJson("string com o json", Response.class);

example passing object (Object name "obj") to json:

Gson gson = new Gson();
String jsonString = gson.toJson(obj);
    
25.01.2018 / 17:26