我想添加如下数组请通过循环帮我这个请帮助我;我的逻辑得到了数组的最后一个图像
for (int i = 0; i < jarray.length(); i++) {
try {
String urlimage = jarray.getJSONObject(i).getString("imageurl");
String name = jarray.getJSONObject(i).getString("imagename");
myarr = new SpacePhoto[]{ new SpacePhoto(urlimage, name),};
} catch (JSONException e) {
e.printStackTrace();
}
}
示例我想要添加如下所示的数组
return new SpacePhoto[]{
// new SpacePhoto("http://i.imgur.com/zuG2bGQ.jpg", "Galaxy"),
// new SpacePhoto("http://i.imgur.com/ovr0NAF.jpg", "Space Shuttle"),
// new SpacePhoto("http://i.imgur.com/n6RfJX2.jpg", "Galaxy Orion"),
// new SpacePhoto("http://i.imgur.com/qpr5LR2.jpg", "Earth"),
// new SpacePhoto("http://i.imgur.com/pSHXfu5.jpg", "Astronaut"),
// new SpacePhoto("http://i.imgur.com/3wQcZeY.jpg", "Satellite"),
答案 0 :(得分:1)
您可以尝试这种方式:
SpacePhoto[] myarr = new SpacePhoto[jarray.length()]
for (int i = 0; i < jarray.length(); i++) {
try {
String urlimage = jarray.getJSONObject(i).getString("imageurl");
String name = jarray.getJSONObject(i).getString("imagename");
myarr[i] = new SpacePhoto(urlimage, name);
} catch (JSONException e) {
e.printStackTrace();
}
}