第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

獲取空的JSONObject值

獲取空的JSONObject值

開心每一天1111 2021-04-01 15:14:26
我正在嘗試創(chuàng)建一個(gè)JSONObject作為下面的代碼。但是Android Studio表示它為空。我的錯(cuò)誤在哪里?我嘗試了兩種不同的方式來創(chuàng)建它。1號(hào)String JSONString = "{" +            "  \"retorno\": {" +            "    \"empresas\": [" +            "      {" +            "        \"cnpj\": \"05.743.645/0001-38\"," +            "        \"razao_social\": \"GISELA TRANSPORTES E DISTRIBUIDORA DE FLORES LTDA - ME\"," +            "        \"endereco\": \"EST RSC-453 (ROTA DO SOL) KM 93,8\"," +            "        \"bairro\": \"BAIRRO ALFANDEGA\"," +            "        \"numero\": 26," +            "        \"complemento\": \"\"," +            "        \"telefone\": \"3462 2749\"," +            "        \"celular\": \"\"," +            "        \"email\": \"giselaflores@giselaflores.com.br\"" +            "      }" +            "    ]" +            "  }" +            "}";try {        JSONObject jsonEmpresa = new JSONObject(JSONString);        String email = jsonEmpresa.getString("email");} catch (JSONException e) {        e.printStackTrace();    }第二名try {        JSONObject jsonEmpresa = new JSONObject();        jsonEmpresa.put("cnpj", "05.743.645/0001-38");        jsonEmpresa.put("razao_social", "GISELA TRANSPORTES E DISTRIBUIDORA DE FLORES LTDA - ME");        jsonEmpresa.put("endereco", "EST RSC-453 (ROTA DO SOL) KM 93,8");        jsonEmpresa.put("bairro", "BAIRRO ALFANDEGA");        jsonEmpresa.put("numero", 26);        jsonEmpresa.put("complemento", "");        jsonEmpresa.put("telefone", "3462 2749");        jsonEmpresa.put("celular", "");        jsonEmpresa.put("email", "giselaflores@giselaflores.com.br");        String email = jsonEmpresa.getString("email");} catch (JSONException e) {        e.printStackTrace();    }字符串電子郵件的值為null,應(yīng)為giselaflores@giselaflores.com.br。當(dāng)我嘗試調(diào)試時(shí),我收到消息jsonEmpresa:“ null”。
查看完整描述

1 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

要獲得給定示例的電子郵件價(jià)值,您應(yīng)該喜歡


 String JSONString = "{" +

                "  \"retorno\": {" +

                "    \"empresas\": [" +

                "      {" +

                "        \"cnpj\": \"05.743.645/0001-38\"," +

                "        \"razao_social\": \"GISELA TRANSPORTES E DISTRIBUIDORA DE FLORES LTDA - ME\"," +

                "        \"endereco\": \"EST RSC-453 (ROTA DO SOL) KM 93,8\"," +

                "        \"bairro\": \"BAIRRO ALFANDEGA\"," +

                "        \"numero\": 26," +

                "        \"complemento\": \"\"," +

                "        \"telefone\": \"3462 2749\"," +

                "        \"celular\": \"\"," +

                "        \"email\": \"giselaflores@giselaflores.com.br\"" +

                "      }" +

                "    ]" +

                "  }" +

                "}";

        try {

            JSONObject jsonEmpresa = new JSONObject(JSONString);

            JSONObject retorno = jsonEmpresa.getJSONObject("retorno");

            JSONArray empresas = retorno.getJSONArray("empresas");

            JSONObject empresa =  empresas.getJSONObject(0);


            String email =empresa.getString("email");


        } catch (JSONException e) {

            e.printStackTrace();

        }


查看完整回答
反對(duì) 回復(fù) 2021-04-18
  • 1 回答
  • 0 關(guān)注
  • 284 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)