2016-09-11 10 views
0

내가 안드로이드에서 발리슛 URL로 연결 오전 :org.json.JSONException : 값 ... - 발리?

private void connectToUrl(String url) { 
    JsonArrayRequest req = new JsonArrayRequest(url, 
      new Response.Listener<JSONArray>() { 
       @Override 
       public void onResponse(JSONArray response) { 
        JSONObject jsonObj = null; 
        try { 
         jsonObj = new JSONObject(response.toString()); 
         JSONArray contacts = jsonObj.getJSONArray("d"); 
         for (int i = 0; i < contacts.length(); i++) { 
          try { 
           JSONObject object = response.getJSONObject(i); 
           Log.i("VALUEDSSDDD", object.getString("urlpic")); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d("Custom Log Error", "Error: " + error.getMessage()); 
      Log.i("ERRRROOORR",error.getMessage()+""); 
     } 
    }); 

    // Adding request to request queue 
    AppController.getInstance().addToRequestQueue(req, tag_json_arry); 
    req.setRetryPolicy(new DefaultRetryPolicy(
      30000, 
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
} 

을하지만 url에 연결할 때 나에게 오류 얻을 :

{ 
    "d": [{ 
     "apiCurrentUserID": 0, 
     "apiCurrentUserName": null, 
     "urlpic": "http://Image.jpg", 
     "Title": "Jim", 
     "FileMusicUrl": "http://video.mp4", 
     "StringDuration": "05':07''", 
     "ViewCount": 57, 
     "DownloadCount": 56, 
     "uploadDate": "/Date(1473550560)/", 
     "MusicID": 192727, 
     "UserID": 0, 
     "Summary": "Some text", 
     "OrderView": null, 
     "ShowDate": "/Date(1473550500)/", 
     "FileSize": "19.15 MB", 
     "RatePlus": null, 
     "RateDash": null, 
     "ChannelID": 0, 
     "ChannelName": null, 
     "CurrentChannelID": 0, 
     "CurrentChannelName": null, 
     "isFollowed": false, 
     "profileImgUserSend": null, 
     "isDisliked": false, 
     "isLiked": false, 
     "isLatered": false, 
     "isFavorited": false, 
     "apiCategories": null, 
     "apiTags": [{ 
      "tageID": "438232", 
      "titleTag": "book" 
     }, { 
      "tageID": "411557", 
      "titleTag": "sounds" 
     }, { 
      "tageID": "365984", 
      "titleTag": "map" 
     }] 
    }], 
    "RowwCount": 0 
} 

I : 여기

org.json.JSONException: Value ..... 

json입니다 json에서 url까지 올라갑니다.

는 편집 :

나는 내 코드를 편집 :

private void connectToUrl(String url) { 
    requestQueue = Volley.newRequestQueue(this); 
    JsonObjectRequest obreq = new JsonObjectRequest(Request.Method.DEPRECATED_GET_OR_POST, url, null, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        JSONObject jsonObj = null; 
        try { 
         jsonObj = new JSONObject(response.toString()); 
         JSONObject contacts = jsonObj.getJSONObject("d"); 
         try { 
          Log.i("VALUEDSSDDD", contacts.getString("urlpic")); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Log.e("Volley", "Error " + error.getMessage()); 
       } 
      } 
    ); 
    requestQueue.add(obreq); 
} 

그러나 나에게 오류 얻을 : 마지막 코드에서

null 

을 나에게 돈을 초래하지만,이 코드에 표시 어떤 결과도 없습니다.

+0

포스트의 완전한 오류 로그 –

답변

1

붙여 넣은 응답은 JSONObject가 아닌 JSONArray입니다. d 값을 JSON 배열로 가져와야합니다.

+0

내가 어떤 결과를 얻을하지 않습니다 JsonObjectRequest에서 사용하지만, 나에게 오류 널 (null)을 얻는다. –

+0

@ android_dev. 고마워. –

+0

@JoJoRoid 도와 드리겠습니다 :) –

0

는 내 문제가 해결 :

private void connectToUrl(String url) { 
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,url,null, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 

        JSONObject jsonObj = null; 
        try { 
         jsonObj = new JSONObject(response.toString()); 
         JSONArray contacts = jsonObj.getJSONArray("d"); 
         for (int i = 0; i < contacts.length(); i++) { 
          try { 
           JSONObject object = contacts.getJSONObject(i); 

          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         } 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d("Custom Log Error", "Error: " + error.getMessage()); 
      Log.i("ERRRROOORR",error.getMessage()+""); 
     } 
    }); 

    // Adding request to request queue 
    AppController.getInstance().addToRequestQueue(req, tag_json_arry); 
    req.setRetryPolicy(new DefaultRetryPolicy(
      30000, 
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
} 
관련 문제