为了账号安全,请及时绑定邮箱和手机立即绑定

如何解析此 JSONObject 以从 twitter 搜索 API 获取数组内的值以获取每条推文?

如何解析此 JSONObject 以从 twitter 搜索 API 获取数组内的值以获取每条推文?

ITMISS 2021-06-11 17:34:12
这是我在使用 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 JSONpublic 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;
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 153 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信