Java代碼: -凌空請求總是陷入錯誤監聽
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "http://sikkimexpress.itstunner.com/api/homenewslist/topnews", new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("HomeNews");
for (int i = 0; i<jsonArray.length();i++){
JSONObject homenews = jsonArray.getJSONObject(i) ;
String newsId = homenews.getString("NewsId");
String dateTime = homenews.getString("DateTime");
String newsType = homenews.getString("NewsType");
String title = homenews.getString("Title");
String description = homenews.getString("Description");
String mainImageURL = homenews.getString("MainImageThumbnail");
System.out.println("Result:- " + newsId + " " + dateTime + " " + newsType + " " + title + " " + description + " " + mainImageURL);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", "ERROR");
}
});
requestQueue.add(jsonObjectRequest);
JSON: -
{
"Status": 0,
"Message": "Sucess"
"HomeNews": [
{
"NewsId": 13,
"DateTime": null,
"NewsType": "latest",
"Title": "Jat quota row: Haryana CM calls all-party meet as stir continues",
"Description": "<p>Jat students block the Rohtak-Delhi road in Rohtak as part of the quota agitation. (Manoj Dhaka/HindustanTimes). Share. Share. Share.</p>",
"MainImageThumbnail": "http://ste.india.com/sites/default/files/2016/02/19/461939-haryana-jat-protest.jpg",
"ReferenceURL": ""
},
{
"NewsId": 15,
"DateTime": null,
"NewsType": "latest",
"Title": "Sports quiz of the week",
"Description": "<p>Which snooker player competing at the Welsh Open said: \"I get so bored at these tournaments. Maybe they should stick an adult creche here to keep us entertained because I just want to go home now.\r\n\r\n\"Today I've had a haircut, I've been in the Chinese, I've been for a coffee, I went to Bill's cafe for a couple of hours, I've had a kip, I went to Marks' and bought a bit of grub. What a day. It's certainly not glamorous.\"?</p>",
"MainImageThumbnail": "http://news.files.bbci.co.uk/vj/live/idt-images/quizzes-sports_weekly_quiz_week7/Snooker_comp_getty_k4960.jpg",
"ReferenceURL": ""
},
]
}
我想解析JSON,但它總是來的Response.ErrorListener。如果狀態= 0且消息成功,則將檢索NewsId,DateTime,標題,描述的值。有人可以幫忙嗎?我接受了互聯網的許可,並檢查了URL並且它正在工作。
url響應是XML而不是JSON – Yazan
如果你有郵遞員,那麼你會看到json – user312456
誰告訴你我沒有使用郵遞員? – Yazan