私はアンドロイドにボレーで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
になっています。
EDIT:
私は私のコードを編集します。
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
は私が結果を示したが、このコードドンで結果はありません。
ポストの完全なエラーログ –