这是我在使用 search/tweets.api 时得到的响应。
{"statuses":[{"created_at":"Sun Jul 29 01:30:52 +0000 2018","id":1023380303648354304,"id_str":"1023380303648354304","text":"RT @FCFSeleccionCol: #FCFSub21 \n\nSemifinal \n\nEn marcha el juego en el Romelio Martínez!\n\nColombia 0 - Haití 0. ⚽⚽. #ColombiaJuegaEnCasa","truncated":false,"entities":{"hashtags":[{"text":"FCFSub21","indices":[21,30]},{"text":"ColombiaJuegaEnCasa","indices":[115,135]}],"symbols":[],"user_mentions":
我无法解析它以获取处于 (created_at, name, text 等) 状态的值
我用这个方法试过了,没用
public void addItems(JSONArray response){
for (int i = 0; i < response.length(); i++ ) {
//convert each object to a Tweet model
//add that twiit model to our data source
//notify the adapter that we've added an item
try {
Tweet tweet = Tweet.fromJSON(response.getJSONObject(i));
tweets.add(tweet);
tweetAdapter.notifyItemInserted(tweets.size() - 1);
} catch (JSONException e){
e.printStackTrace();
}
}
}
这是 fromJSON 方法:
//deserialize the JSON
public static Tweet fromJSON(JSONObject jsonObject) throws JSONException{
Tweet tweet = new Tweet();
//extract the values from JSON
tweet.body = jsonObject.getString("text");
tweet.uid = jsonObject.getLong("id");
tweet.createdAt = jsonObject.getString("created_at");
tweet.user = User.fromJSON(jsonObject.getJSONObject("user"));
//tweet.extendedEntities = ExtendedEntities.fromJSON
return tweet;
相关分类