Convert JSONArray to Object

0

I'm having trouble converting an array I get via webservice

CustomRequest request = new CustomRequest(Request.Method.GET,
            "http://" + url + "/service/usuario/mural",
            null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    ocultaProgressBar();
                    Gson gson = new Gson();
                    mural = new ArrayList<>();
                    for (int i = 0, tamI = response.length(); i < tamI; i++) {
                        try {
                            Configuracao configuracao = new Configuracao();
                            configuracao = gson.fromJson(response.getString(i), Configuracao.class);
                            mural.add(configuracao);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    iniciarFragmentoHome();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                    Log.e("Erro",error.toString());
                    ocultaProgressBar();

                }
            });

In the case of java, I would like to do the following:

Alamofire.request(urlbusca, method: .get)
        .responseJSON { response in
            if(response.result.isSuccess){
                let jsonc = JSON(response.result.value!)
                print(jsonc)

                let resData = jsonc[0].arrayObject as! String
                print(resData)
                let conf = Configuracao(json:resData)
                self.mensagens.append(conf)

                print(self.mensagens)

                if self.mensagens.count>0{
                    print("ok")
                    self.tbInicio.reloadData()
                }
                else {
                    let alert = UIAlertController(title: "Alerta", message: "Sem conexão com a internet!", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "ok", style: .default) { action in
                        // perhaps use action.title here
                    })
                    self.present(alert, animated: true)
                }
            }


    }

I do not know how to use get to retrieve the object

    
asked by anonymous 17.02.2017 / 10:51

1 answer

0
    Alamofire.request(urlbusca, method: .get)
        .responseJSON { response in
            if(response.result.isSuccess){
                let jsonc = JSON(response.result.value!)
                for config  in jsonc{
                    let confi = config.1.rawString()
                    let conf = Configuracao(json:confi)
                    self.mensagens.append(conf)


                }

                if self.mensagens.count>0{
                    let appDelegate = UIApplication.shared.delegate as! AppDelegate
                    appDelegate.mural = self.mensagens

                    self.tbInicio.reloadData()
                }
                else {
                    let alert = UIAlertController(title: "Alerta", message: "Sem conexão com a internet!", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "ok", style: .default) { action in
                        // perhaps use action.title here
                    })
                    self.present(alert, animated: true)
                }
            }


    }
    
23.03.2017 / 16:31