我想将对象数组转换为for循环内的字符串数组。获取一组对象并转换为字符串数组?
我从对象中提取属性title
我有几个title
字符串,现在我想将它传递给一个新的数组?
JSONArray shots = response.getJSONArray("shots");
for (int i=0; i < shots.length(); i++) {
// play with data
JSONObject post = shots.getJSONObject(i);
String title = post.getString("title");
// turn title into an array of strings??
}
编辑:
我想这
String[] mStrings = new String[15];
JSONArray shots = response.getJSONArray("shots");
for (int i=0; i < shots.length(); i++) {
// play with data
JSONObject post = shots.getJSONObject(i);
String title = post.getString("title");
//Log.d("this is my array", "arr: " + title);
mStrings[i] = title;
}
Log.d("this is my array", "arr: " + mStrings);
的Log.d
结果是D/this is my array﹕ arr: [Ljava.lang.String;@4294e620
看起来你已经做到了。您已将每个标题存储为String数组的一个元素。我在这里不了解什么? – jrahhali
它基本上没有在日志中显示我。所以我不确定 –
谢谢你们。我想我明白了。 –