嗨我一直得到这个错误,我试图从Twitter通过JSON鸣叫,似乎无法摆脱这个“ARR”。我需要做一个不同的循环?我确实尝试过,但它一直返回相同的错误。只能遍历一个数组或java.lang.Iterable的实例
public ArrayList<Tweet> getTweets(String searchTerm, int page) {
String searchUrl =
"http://search.twitter.com/[email protected]"
+ searchTerm + "&rpp=100&page=" + page;
ArrayList<Tweet> tweets =
new ArrayList<Tweet>();
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(searchUrl);
ResponseHandler<String> responseHandler =
new BasicResponseHandler();
String responseBody = null;
try {
responseBody = client.execute(get, responseHandler);
} catch(Exception ex) {
ex.printStackTrace();
}
JSONObject jsonObject = null;
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(responseBody);
jsonObject=(JSONObject)obj;
}catch(Exception ex){
Log.v("TEST","Exception: " + ex.getMessage());
}
JSONArray<Object> arr = null;
try {
Object j = jsonObject.get("results");
arr = (JSONArray)j;
} catch(Exception ex){
Log.v("TEST","Exception: " + ex.getMessage());
}
for(Object t : arr) {
Tweet tweet = new Tweet(
((JSONObject)t).get("from_user").toString(),
((JSONObject)t).get("text").toString(),
((JSONObject)t).get("profile_image_url").toString()
);
tweets.add(tweet);
}
return tweets;
}
请帮忙!!
HAVA这里看看吧! [迭代json数组](http://stackoverflow.com/questions/3408985/json-array-iteration-in-android-java) – Vossi 2012-03-23 13:33:27