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

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

值無法轉(zhuǎn)換為 JSON 數(shù)組

值無法轉(zhuǎn)換為 JSON 數(shù)組

UYOU 2021-12-10 12:32:38
這是給我?guī)韱栴}的功能:    public String URLToJson() {    String result = "";    String jsonString = ReadingURL(" here goes my URL that reads a JSON ");    JSONObject jsonResult = null;    try {        jsonResult = new JSONObject(jsonString);        JSONArray data = jsonResult.getJSONArray("Configuracion");        if (data != null) {            for (int i = 0; i <= data.length(); i++) {                result =  result + "Dirección: " + data.getJSONObject(i).getString("Direccion") + "\n";                result =  result + "Cédula: " + data.getJSONObject(i).getString("Cedula") + "\n";                result =  result + "Nombre: : " + data.getJSONObject(i).getString("Nombre") + "\n";                result =  result + "Teléfono : " + data.getJSONObject(i).getString("Telefono") + "\n";                result =  result + "Hacienda: " + data.getJSONObject(i).getString("Hacienda") + "\n";            }        }        return result;    }catch (JSONException e){        e.printStackTrace();        return "Error Reading JSON Data";    }}然后出現(xiàn)了這個(gè):`W/System.err: org.json.JSONException: Value {"Direccion":"Somewhere","Cedula":"111111","Nombre":"Something","Telefono":"2222-2440","Hacienda":"Something"} at Configuracion of type org.json.JSONObject cannot be converted to JSONArray        at org.json.JSON.typeMismatch(JSON.java:100)W/System.err:     at org.json.JSONObject.getJSONArray(JSONObject.java:588)        at com.example.user.mypos.PrintManager.URLToJson(PrintManager.java:977)W/System.err:     at com.example.user.mypos.PrintManager$4.run(PrintManager.java:917)        at java.lang.Thread.run(Thread.java:818)W/System.err: org.json.JSONException: Value { the values that are supposed to be }  of type org.json.JSONObject cannot be converted to JSONArray`ReadingURL 基本上讀取 URL 的內(nèi)容,該內(nèi)容在字符串中包含 JSON。
查看完整描述

2 回答

?
素胚勾勒不出你

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

從異常中可以清楚地看出,URL 返回JSON 字符串的類型是 JSONObject 而不是 JSONArray

值 { 應(yīng)該是 } 類型 org.json.JSONObject 的值無法轉(zhuǎn)換為 JSONArray

JSON 對(duì)象將以 { 開頭 & 以 } 結(jié)尾

{ "KEY1":"VALUE1", "KEY2":"VALUE2" }

并且 JSON 數(shù)組將以 [ 開頭并以 ] 結(jié)尾。

[
{"KEY1":"VALUE1","KEY2":"VALUE2"},{"KEY1":"VALUE1","KEY2":"VALUE2"}
]

因此,您收到此異常是因?yàn)槟趪L試將 JSON 對(duì)象轉(zhuǎn)換為 JSON 數(shù)組。


查看完整回答
反對(duì) 回復(fù) 2021-12-10
?
江戶川亂折騰

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

public String URLToJson() {

    String result = "";

    String jsonString = ReadingURL("http://deliciasmarinas.avancari.co.cr/app/tiquete.php?factura=414696772");

    JSONObject jsonResult = null;

    try {

        jsonResult = new JSONObject(jsonString);

            for (int i = 0; i <= jsonResult.length(); i++) {

                result =  result + "Dirección: " + jsonResult.get("Direccion") + "\n";

                result =  result + "Cédula: " + jsonResult.get("Cedula") + "\n";

                result =  result + "Nombre: : " + jsonResult.get("Nombre") + "\n";

                result =  result + "Teléfono : " + jsonResult.get("Telefono") + "\n";

                result =  result + "Hacienda: " + jsonResult.get("Hacienda") + "\n";

            }

        return result;

    }catch (JSONException e){

        e.printStackTrace();

        return "Error Reading JSON Data";

    }

}

現(xiàn)在它只顯示


W/System.err: org.json.JSONException: No value for Direccion

        at org.json.JSONObject.get(JSONObject.java:389)

W/System.err:     at com.example.user.mypos.PrintManager.URLToJson(PrintManager.java:978)

        at com.example.user.mypos.PrintManager$4.run(PrintManager.java:917)

        at java.lang.Thread.run(Thread.java:818)


查看完整回答
反對(duì) 回復(fù) 2021-12-10
  • 2 回答
  • 0 關(guān)注
  • 227 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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