2016-09-25 3 views
0

JSON을 사용하고 Android listview에 표시하려고합니다. 안드로이드Error : org.json.JSONException : java.lang.String 유형의 http 값을 JSONObject로 변환 할 수 없습니다.

{ 
    "meta": { 
     "limit": 20, 
     "next": null, 
     "offset": 0, 
     "previous": null, 
     "total_count": 5 
    }, 
    "objects": [{ 
     "acad_rating": "4.58", 
     "address": "Karawal Nagar Delhi-110094", 
     "adm_close": "5/2/2016", 
     "adm_open": "1/1/2016", 
     "affiliated_till": "31/3/2017", 
     "area": "Karawal Nagar (West)", 
     "average_board_perc": null, 
     "boardhighsec": "Cbse", 
     "boardsec": "Cbse", 
     "books_in_lib": 9684, 
     "boyperc": "72.00", 
     "category": " Primary With Upper Primary And Secondary And Higher Secondary(1-12) ", 
     "cce_impl": true, 
     "city": "Delhi", 
     "cityslug": "delhi", 
     "coed": "Co-Ed", 
     "computer_aid_learn": true, 
     "description": null, 
     "district": "North East Delhi", 
     "drinking_water": "Tap Water", 
     "email": "[email protected]", 
     "facilities_rating": "5.00", 
     "fax": "4132622661", 
     "girlperc": "28.00", 
     "good_classrooms": 21, 
     "grad_teachers": "92.16", 
     "highestclass": 12, 
     "image": null, 
     "library": true, 
     "lowestclass": 1, 
     "medical_checkup_last_yr": true, 
     "medium": " English ", 
     "mid_day_meal": "Na", 
     "minage": 3, 
     "name": "Sardar Patel Public Sr.Sec. School", 
     "no_classrooms": 21, 
     "no_computers": 35, 
     "overall_rating": "4.33", 
     "padmin": 15, 
     "parents_smc": 2, 
     "phone": "22934441", 
     "pincode": 110094, 
     "playground": true, 
     "pqualification": "B.A., M.Phil, M.Ed.", 
     "principal": "Mohd Zahid Khan", 
     "pteach": 9, 
     "ptotal": 24, 
     "ramp": true, 
     "rating": "3.5", 
     "residential_school": false, 
     "resource_uri": "/api/schools/7030327101/", 
     "school_mgt_com": true, 
     "schoolid": "7030327101", 
     "schooltype": "Private Unaided School", 
     "since": 1985, 
     "slug": "sardar-patel-public-srsec-school", 
     "student_teacher": "33.45", 
     "total_seats": 0, 
     "total_smc": 18, 
     "total_students": 1706, 
     "total_teachers": 51, 
     "totalews": 0, 
     "trust": "Geeta Educational Society, Shera", 
     "tuition": 0, 
     "website": "http://www.auroville.org.in", 
     "workdays_pr": 240, 
     "written_test": true, 
     "zone": "4" 
    }] 
} 

내 AsyncTask를 :

은 JSON이다 내가 받고있는 이유

@Override 
    protected void onPostExecute(String result) { 

     try { 
      JSONObject jObj = new JSONObject(result); 
      String notes = jObj.getString("objects"); 
     } catch (JSONException e) { 
      Log.e("JSONException", "Error: " + e.toString()); 
     } 

확실하지 오류 : 당신이

E/JSONException: Error: org.json.JSONException: Value http of type java.lang.String cannot be converted to JSONObject 
+0

JSONObject로 변환하기 전에 결과 값을 기록하십시오 –

+0

오류가 '값 http'이므로 doInBackround에서 올바른 값을 반환하지 않는 것 같습니다. –

+1

감사합니다. 도움을 받아서 URL을 반환했으나하지 않았습니다. json 문자열. 고마워 ! – headcrabz

답변

0

문자열 결과를 전달하는 onPostExecute() 메소드는 JSON 문자열이 아닙니다.

또한 doInBackground() 내에서 JSON 문자열을 구문 분석하지 않는 이유는 무엇입니까? 가능한 경우 백그라운드 스레드가 이러한 작업을 수행하는 더 좋은 옵션입니다. 가능한 경우 UI 스레드에서 조작을 위해 UI 스레드에서 실행되는 onPostExecute() 메소드를 예약하십시오. 그리고 JSON 구문 분석은 확실히 백그라운드에서 수행 할 수 있습니다.

관련 문제