문제 JsonObject 구문 분석이 jsonarray로 변환 할 수 없음

지퍼 라인

안녕하세요 . 내 웹 서비스에 json 데이터 줄이 있습니다. 모든 Json 데이터는 URL과 링크 만이 형식으로 사용할 수 있습니다. 그래서 내가 아는 것처럼 JsonObject입니다. Short는 내가 요청했고 결과는 항상 URL로 끝납니다. 따라서 출력은 다음과 같습니다.

{"Url":"www.google.com"}

이것이 내가 한 일

            JSONArray json = jParser.getJSONFromUrl(url);

            try {
                ListBasedList.clear();
                //for each loop til JSON data
                   for(int i = 0; i < json.length(); i++){
                        JSONObject c = json.getJSONObject(i);

                    String json_url = c.getString(TAG_Url);

                    if(json_url.equals(0) && json_url.equals(""))
                    {
                         LinearLayout lin_footer = (LinearLayout) findViewById(R.id.footer_layoutMain);
                         lin_footer.setVisibility(View.GONE);
                    }

                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put(TAG_Url, json_url);

                    ListBasedList.add(map);
                   }
            } catch (JSONException e) {
                e.printStackTrace();
                Log.e("JSON Parser fejl", "fejl da man prøve og hente data fra server " + e.toString());
            }
            return null;
        }

여기에서 오류 발생

나에게 이것을 말하는 logcat :

JSONObject는 jsonarray로 변환 할 수 없습니다.

그렇다면 오류 대신 링크를 어떻게 가질 수 있습니까?

업데이트 # 1-> Logcat 전체 오류

    10-01 13:34:45.685: E/JSON Parser(24256): Error parsing data org.json.JSONException: Value {"url":"www.google.com"} of type org.json.JSONObject cannot be converted to JSONArray

업데이트 # 2-> JsonParser 클래스

public class JSONParser {
    static InputStream is = null;
    static String json = "";
    JSONArray jsonarr=null;
    // konstruktor
    public JSONParser() {
    }

    public JSONArray getJSONFromUrl(String url) {
         JSONArray jsonarr=null;

         // HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // json array paser til string
          try {
                jsonarr = new JSONArray(json);
                } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // retunerer json object tilbage
        return jsonarr;
        }
         }
판 카이 쿠마르

응답에서 단일 Json 객체를 얻습니다. 으로는 {"Url":"www.google.com"}된 JSONObject이다.

그래서 라인

JSONArray json = jParser.getJSONFromUrl(url);

이어야한다

JSONObject json = jParser.getJSONFromUrl(url);

그리고 데이터를 읽는 동안에는

String json_url = json.getString(TAG_Url);

for 루프를 사용하는 대신.


업데이트 된 클래스보기

public class JSONParser {
    static InputStream is = null;
    static String json = "";
    JSONObject jsonObject = null; // Updated here

    // konstruktor
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        jsonObject = null; // Updated here

        // HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // json array paser til string
        try {
            jsonObject = new JSONObject(json); // Updated here
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // retunerer json object tilbage
        return jsonObject; // Updated here
    }
}

이것은 현재 json에서 작동합니다. 참조 // Updated here내가 업데이트 한 내용을 알 수 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Android JSON 구문 분석 'org.json.JSONObject 유형의 데이터를 JSONArray로 변환 할 수 없음'오류

분류에서Dev

Android json 구문 분석 오류-JSONArray를 JSONObject로 변환 할 수 없습니다.

분류에서Dev

Android json 구문 분석 오류-JSONArray를 JSONObject로 변환 할 수 없습니다.

분류에서Dev

데이터 구문 분석 오류-문자열을 JSONObject로 변환 할 수 없습니다.

분류에서Dev

데이터 구문 분석 오류 org.json.JSONException : 값 문자열을 JSONArray로 변환 할 수 없습니다.

분류에서Dev

JSONArray로 JSONObject 구문 분석

분류에서Dev

JSONArray로 JSONObject 구문 분석

분류에서Dev

JSONArray로 JSONObject 구문 분석

분류에서Dev

JsonObject로 JsonArray 구문 분석

분류에서Dev

JSON 구문 분석 용 Android 모델에 ClassCastException이 표시됨 : com.google.gson.JsonObject를 com.google.gson.JsonArray로 캐스트 할 수 없음

분류에서Dev

내 안드로이드 프로젝트에서 "JSONObject를 JSONArray로 변환 할 수 없습니다"와 같이 JSON을 구문 분석하는 동안 예외가 표시되는 이유를 알 수 없습니다.

분류에서Dev

Android JSON 구문 분석 issue-java.lang.string을 JSONObject로 변환 할 수 없습니다.

분류에서Dev

데이터 구문 분석 오류 org.json.JSONException : 값 <br> <java.lang.String 유형의 테이블을 JSONObject로 변환 할 수 없습니다.

분류에서Dev

JSONObject를 JSONArray로 변환 할 수 없음-Android

분류에서Dev

JSON 데이터를 POJO로 구문 분석 할 수 없음

분류에서Dev

jsonobject는 jsonarray 중첩 jsonarray android로 변환 할 수 없습니다.

분류에서Dev

데이터 구문 분석 오류 org.json.JSONException : java.lang.String 유형의 값 <br을 JSONArray로 변환 할 수 없습니다.

분류에서Dev

변환 부동 문자열을 int로 구문 분석 할 수없는 이유는 무엇입니까?

분류에서Dev

변환기 구성 실패 : 오류 : C를 구문 분석 할 수 없음 :

분류에서Dev

Excel을 json 배열로 변환 할 때 날짜를 구문 분석 할 수 없음

분류에서Dev

md를 pdf로 변환 할 때 pandoc "yaml 헤더를 구문 분석 할 수 없음"

분류에서Dev

JSONObject를 Java 문자열로 변환 할 수 있음

분류에서Dev

이 오류 org.json.JSONObject를 JSONArray로 변환 할 수 없습니다.

분류에서Dev

InputBox의 데이터를 정수로 구문 분석 할 수 없음 (Visual Basic for Excel)

분류에서Dev

이 구문 분석 문제를 이해할 수 없습니다.

분류에서Dev

JSONArray java.lang.String을 JSONObject로 변환 할 수 없습니다

분류에서Dev

jsonarray를 jsonobject logcat 오류로 변환 할 수 없습니다.

분류에서Dev

android org.json.JSONArray를 JSONObject로 변환 할 수 없습니까?

분류에서Dev

필드 이름을 알 수없는 경우 jsonObject 구문 분석

Related 관련 기사

  1. 1

    Android JSON 구문 분석 'org.json.JSONObject 유형의 데이터를 JSONArray로 변환 할 수 없음'오류

  2. 2

    Android json 구문 분석 오류-JSONArray를 JSONObject로 변환 할 수 없습니다.

  3. 3

    Android json 구문 분석 오류-JSONArray를 JSONObject로 변환 할 수 없습니다.

  4. 4

    데이터 구문 분석 오류-문자열을 JSONObject로 변환 할 수 없습니다.

  5. 5

    데이터 구문 분석 오류 org.json.JSONException : 값 문자열을 JSONArray로 변환 할 수 없습니다.

  6. 6

    JSONArray로 JSONObject 구문 분석

  7. 7

    JSONArray로 JSONObject 구문 분석

  8. 8

    JSONArray로 JSONObject 구문 분석

  9. 9

    JsonObject로 JsonArray 구문 분석

  10. 10

    JSON 구문 분석 용 Android 모델에 ClassCastException이 표시됨 : com.google.gson.JsonObject를 com.google.gson.JsonArray로 캐스트 할 수 없음

  11. 11

    내 안드로이드 프로젝트에서 "JSONObject를 JSONArray로 변환 할 수 없습니다"와 같이 JSON을 구문 분석하는 동안 예외가 표시되는 이유를 알 수 없습니다.

  12. 12

    Android JSON 구문 분석 issue-java.lang.string을 JSONObject로 변환 할 수 없습니다.

  13. 13

    데이터 구문 분석 오류 org.json.JSONException : 값 <br> <java.lang.String 유형의 테이블을 JSONObject로 변환 할 수 없습니다.

  14. 14

    JSONObject를 JSONArray로 변환 할 수 없음-Android

  15. 15

    JSON 데이터를 POJO로 구문 분석 할 수 없음

  16. 16

    jsonobject는 jsonarray 중첩 jsonarray android로 변환 할 수 없습니다.

  17. 17

    데이터 구문 분석 오류 org.json.JSONException : java.lang.String 유형의 값 <br을 JSONArray로 변환 할 수 없습니다.

  18. 18

    변환 부동 문자열을 int로 구문 분석 할 수없는 이유는 무엇입니까?

  19. 19

    변환기 구성 실패 : 오류 : C를 구문 분석 할 수 없음 :

  20. 20

    Excel을 json 배열로 변환 할 때 날짜를 구문 분석 할 수 없음

  21. 21

    md를 pdf로 변환 할 때 pandoc "yaml 헤더를 구문 분석 할 수 없음"

  22. 22

    JSONObject를 Java 문자열로 변환 할 수 있음

  23. 23

    이 오류 org.json.JSONObject를 JSONArray로 변환 할 수 없습니다.

  24. 24

    InputBox의 데이터를 정수로 구문 분석 할 수 없음 (Visual Basic for Excel)

  25. 25

    이 구문 분석 문제를 이해할 수 없습니다.

  26. 26

    JSONArray java.lang.String을 JSONObject로 변환 할 수 없습니다

  27. 27

    jsonarray를 jsonobject logcat 오류로 변환 할 수 없습니다.

  28. 28

    android org.json.JSONArray를 JSONObject로 변환 할 수 없습니까?

  29. 29

    필드 이름을 알 수없는 경우 jsonObject 구문 분석

뜨겁다태그

보관