我的 android 应用程序中有一个奇怪的问题。在一种方法中,我这样做:
try {
String r = responseBody.toString();
JSONArray jArray = new JSONArray(r);
categorys = new String[jArray.length()];
idcategory = new Integer[jArray.length()];
System.out.println("lung " + jArray.length());
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsdata = jArray.getJSONObject(i);
String idcat = jsdata.getString("id_category");
idcategory[i] = Integer.valueOf(idcat);
System.out.println("Id " + idcat);
String namecategory = jsdata.getString("category_name");
categorys[i] = namecategory;
System.out.println("Category name " + namecategory);
}
一切正常,我从服务器获取类别和类别的 ID。在另一种方法中,我这样做(对于其他响应):
try {
String re = responseBody.toString();
JSONArray jArray = new JSONArray(re);
System.out.println("lung " + jArray.length());
titlephotos = new String[jArray.length()];
photolink=new String[jArray.length()];
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsdata = jArray.getJSONObject(i);
String titlephoto = jsdata.getString("title");
System.out.println("titlu photo " + titlephoto);
titlephotos[i] = titlephoto;
String linkphoto=jsdata.getString("view");
System.out.println("link photo"+ linkphoto);
photolink[i]=linkphoto;
}
}catch(JSONException e) {
System.out.println("You are in catch");
}
然后我只得到一张标题照片,然后我从 catch() 收到消息。如果我不放
String linkphoto=jsdata.getString("photo link");
System.out.println("link photo"+ linkphoto);
photolink[i]=linkphoto;
我得到所有的标题。我不明白问题出在哪里,因为方法相似,第一个效果很好。任何人都可以帮忙吗?
谢谢...