java - 如何解析这个 JSONObject 以从 twitter 搜索 API 获取数组内的值来获取每条推文(名称、正文)?

标签 java android-json android-async-http sttwitterapi

这是我使用 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":[{"screen_name":"FCFSeleccionCol","name":"Selección Colombia","id":1117317140,"id_str":"1117317140","indices":[3,19]}],"urls":[]},"metadata":{"iso_language_code":"es","result_type":"recent"},"source":"<a href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\">Twitter for Android<\/a>","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":905605889859743745,"id_str":"905605889859743745","name":"Jesus David💯","screen_name":"ReyDavid420","location":"Barranquilla, Colombia","description":"Barranquillero, actor, compositor, rapero y futbolista.","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":2,"friends_count":67,"listed_count":0,"created_at":"Thu Sep 07 01:37:24 +0000 2017","favourites_count":593,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":770,"lang":"es","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"F5F8FA","profile_background_image_url":null,"profile_background_image_url_https":null,"profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1010626181044072449\/oRCkMA1g_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1010626181044072449\/oRCkMA1g_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/905605889859743745\/1504748847","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Sun Jul 29 00:06:15 +0000 2018","id":1023359010630758400,"id_str":"1023359010630758400","text":"#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":[0,9]},{"text":"ColombiaJuegaEnCasa","indices":[94,114]}],"symbols":[],"user_mentions":[],"urls":[]},"metadata":{"iso_language_code":"es","result_type":"recent"},"source":"<a href=\"http:\/\/twitter.com\" rel=\"nofollow\">Twitter Web Client<\/a>","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":1117317140,"id_str":"1117317140","name":"Selección Colombia","screen_name":"FCFSeleccionCol","location":"","description":"Cuenta Oficial Selecciones Colombia de Fútbol \/ Federación Colombiana de Fútbol. ⚽️🇨🇴","url":"https:\/\/t.co\/bdS4TJcR5h","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/bdS4TJcR5h","expanded_url":"http:\/\/www.fcf.com.co\/","display_url":"fcf.com.co","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":4572748,"friends_count":54,"listed_count":3734,"created_at":"Thu Jan 24 17:29:53 +0000 2013","favourites_count":37,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":true,"statuses_count":15083,"lang":"es","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"F5EC3D","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1017800505978957824\/1d1KAGzZ_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1017800505978957824\/1d1KAGzZ_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/1117317140\/1531348783","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":13,"favorite_count":71,"favorited":false,"retweeted":false,"lang":"es"},"is_quote_status":false,"retweet_count":13,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"es"},{"created_at":"Sun Jul 29 01:30:50 +0000 2018","id":1023380295473684481,"id_str":"1023380295473684481","text":"RT @radafil_diaz: Señores Haiti le gana a Colombian en los Juegos Centro Americano y del Caribe, bien por nuestro vecino mientra @fedofutbo…","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"radafil_diaz","name":"Radafil Diaz","id":816700741339516930,"id_str":"816700741339516930","indices":[3,16]}],"urls":[]},"metadata":{"iso_language_code":"es","result_type":"recent"},"source":"<a href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\">Twitter for Android<\/a>","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":706612947,"id_str":"706612947","name":"Miguel Gil","screen_name":"mgil047","location":"La Vega, Dominican Republic","description":"Lic. Adm de empresas, Tec. Informático, amante del fútbol, cronista transmisión del atlético vega real, \nsiempre se puede mejorar","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":342,"friends_count":556,"listed_count":5,"created_at":"Wed Oct 09 16:31:19 +0000 2013","favourites_count":1201,"utc_offset":null,"time_zone":null,"geo_enabled":true,"verified":false,"statuses_count":3015,"lang":"es","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/998583089893818369\/Ape7HNbM_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/998583089893818369\/Ape7HNbM_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/706612947\/1425593955","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":true,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Sun Jul 29 01:29:27 +0000 2018","id":1023379945064681472,"id_str":"1023379945064681472","text":"Señores Haiti le gana a Colombian en los Juegos Centro Americano y del Caribe, bien por nuestro vecino mientra… https:\/\/t.co\/p7Z4xNKEIO","truncated":true,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/p7Z4xNKEIO","expanded_url":"https:\/\/twitter.com\/i\/web\/status\/1023379945064681472","display_url":"twitter.com\/i\/web\/status\/1…","indices":[112,135]}]},"metadata":{"iso_language_code":"es","result_type":"recent"},"source":"<a href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\">Twitter for Android<\/a>","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":816700741339516930,"id_str":"816700741339516930","name":"Radafil Diaz","screen_name":"radafil_diaz","location":"Vivo en Panama, Dominicano de ","description":"Amante del deportes dominicano, Beseball,Basqueball, y mi pacion por el futbol, no tiene limite, Amante enamorado Del Barcelona FC, y Atleticos Vega Real!!","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":374,"friends_count":635,"listed_count":3,"created_at":"Wed Jan 04 17:40:05 +0000 2017","favourites_count":86379,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":27444,"lang":"es","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"F5F8FA","profile_background_image_url":null,"profile_background_image_url_https":null,"profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1015056769138257923\/YIMDdGlX_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1015056769138257923\/YIMDdGlX_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/816700741339516930\/1531107483","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":1,"favorite_count":1,"favorited":false,"retweeted":false,"lang":"es"},"is_quote_status":false,"retweet_count":1,"favorite_count":0,"favorited":false,"retweeted":false,"lang":"es"}],"search_metadata":{"completed_in":0.042,"max_id":1023380303648354304,"max_id_str":"1023380303648354304","next_results":"?max_id=1023380295473684480&q=Haiti&count=2&include_entities=1","query":"Haiti","refresh_url":"?since_id=1023380303648354304&q=Haiti&include_entities=1","count":2,"since_id":0,"since_id_str":"0"}}

我无法解析它以获取状态值(created_at、名称、文本等)

这个方法我试过了,没用

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;

最佳答案

查看此示例如何解析 json && 获取数据。

String str = "{\"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\":[{\"screen_name\":\"FCFSeleccionCol\",\"name\":\"Selección Colombia\",\"id\":1117317140,\"id_str\":\"1117317140\",\"indices\":[3,19]}],\"urls\":[]},\"metadata\":{\"iso_language_code\":\"es\",\"result_type\":\"recent\"},\"source\":\"<a href=\\\"http:\\/\\/twitter.com\\/download\\/android\\\" rel=\\\"nofollow\\\">Twitter for Android<\\/a>\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":905605889859743745,\"id_str\":\"905605889859743745\",\"name\":\"Jesus David\uD83D\uDCAF\",\"screen_name\":\"ReyDavid420\",\"location\":\"Barranquilla, Colombia\",\"description\":\"Barranquillero, actor, compositor, rapero y futbolista.\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":2,\"friends_count\":67,\"listed_count\":0,\"created_at\":\"Thu Sep 07 01:37:24 +0000 2017\",\"favourites_count\":593,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":770,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"F5F8FA\",\"profile_background_image_url\":null,\"profile_background_image_url_https\":null,\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/1010626181044072449\\/oRCkMA1g_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/1010626181044072449\\/oRCkMA1g_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/905605889859743745\\/1504748847\",\"profile_link_color\":\"1DA1F2\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"created_at\":\"Sun Jul 29 00:06:15 +0000 2018\",\"id\":1023359010630758400,\"id_str\":\"1023359010630758400\",\"text\":\"#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\":[0,9]},{\"text\":\"ColombiaJuegaEnCasa\",\"indices\":[94,114]}],\"symbols\":[],\"user_mentions\":[],\"urls\":[]},\"metadata\":{\"iso_language_code\":\"es\",\"result_type\":\"recent\"},\"source\":\"<a href=\\\"http:\\/\\/twitter.com\\\" rel=\\\"nofollow\\\">Twitter Web Client<\\/a>\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":1117317140,\"id_str\":\"1117317140\",\"name\":\"Selección Colombia\",\"screen_name\":\"FCFSeleccionCol\",\"location\":\"\",\"description\":\"Cuenta Oficial Selecciones Colombia de Fútbol \\/ Federación Colombiana de Fútbol. ⚽️\uD83C\uDDE8\uD83C\uDDF4\",\"url\":\"https:\\/\\/t.co\\/bdS4TJcR5h\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"https:\\/\\/t.co\\/bdS4TJcR5h\",\"expanded_url\":\"http:\\/\\/www.fcf.com.co\\/\",\"display_url\":\"fcf.com.co\",\"indices\":[0,23]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":4572748,\"friends_count\":54,\"listed_count\":3734,\"created_at\":\"Thu Jan 24 17:29:53 +0000 2013\",\"favourites_count\":37,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":true,\"statuses_count\":15083,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"F5EC3D\",\"profile_background_image_url\":\"http:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/1017800505978957824\\/1d1KAGzZ_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/1017800505978957824\\/1d1KAGzZ_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/1117317140\\/1531348783\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"is_quote_status\":false,\"retweet_count\":13,\"favorite_count\":71,\"favorited\":false,\"retweeted\":false,\"lang\":\"es\"},\"is_quote_status\":false,\"retweet_count\":13,\"favorite_count\":0,\"favorited\":false,\"retweeted\":false,\"lang\":\"es\"},{\"created_at\":\"Sun Jul 29 01:30:50 +0000 2018\",\"id\":1023380295473684481,\"id_str\":\"1023380295473684481\",\"text\":\"RT @radafil_diaz: Señores Haiti le gana a Colombian en los Juegos Centro Americano y del Caribe, bien por nuestro vecino mientra @fedofutbo…\",\"truncated\":false,\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[{\"screen_name\":\"radafil_diaz\",\"name\":\"Radafil Diaz\",\"id\":816700741339516930,\"id_str\":\"816700741339516930\",\"indices\":[3,16]}],\"urls\":[]},\"metadata\":{\"iso_language_code\":\"es\",\"result_type\":\"recent\"},\"source\":\"<a href=\\\"http:\\/\\/twitter.com\\/download\\/android\\\" rel=\\\"nofollow\\\">Twitter for Android<\\/a>\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":706612947,\"id_str\":\"706612947\",\"name\":\"Miguel Gil\",\"screen_name\":\"mgil047\",\"location\":\"La Vega, Dominican Republic\",\"description\":\"Lic. Adm de empresas, Tec. Informático, amante del fútbol, cronista transmisión del atlético vega real, \\nsiempre se puede mejorar\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":342,\"friends_count\":556,\"listed_count\":5,\"created_at\":\"Wed Oct 09 16:31:19 +0000 2013\",\"favourites_count\":1201,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":true,\"verified\":false,\"statuses_count\":3015,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/998583089893818369\\/Ape7HNbM_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/998583089893818369\\/Ape7HNbM_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/706612947\\/1425593955\",\"profile_link_color\":\"1DA1F2\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweeted_status\":{\"created_at\":\"Sun Jul 29 01:29:27 +0000 2018\",\"id\":1023379945064681472,\"id_str\":\"1023379945064681472\",\"text\":\"Señores Haiti le gana a Colombian en los Juegos Centro Americano y del Caribe, bien por nuestro vecino mientra… https:\\/\\/t.co\\/p7Z4xNKEIO\",\"truncated\":true,\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[],\"urls\":[{\"url\":\"https:\\/\\/t.co\\/p7Z4xNKEIO\",\"expanded_url\":\"https:\\/\\/twitter.com\\/i\\/web\\/status\\/1023379945064681472\",\"display_url\":\"twitter.com\\/i\\/web\\/status\\/1…\",\"indices\":[112,135]}]},\"metadata\":{\"iso_language_code\":\"es\",\"result_type\":\"recent\"},\"source\":\"<a href=\\\"http:\\/\\/twitter.com\\/download\\/android\\\" rel=\\\"nofollow\\\">Twitter for Android<\\/a>\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":816700741339516930,\"id_str\":\"816700741339516930\",\"name\":\"Radafil Diaz\",\"screen_name\":\"radafil_diaz\",\"location\":\"Vivo en Panama, Dominicano de \",\"description\":\"Amante del deportes dominicano, Beseball,Basqueball, y mi pacion por el futbol, no tiene limite, Amante enamorado Del Barcelona FC, y Atleticos Vega Real!!\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":374,\"friends_count\":635,\"listed_count\":3,\"created_at\":\"Wed Jan 04 17:40:05 +0000 2017\",\"favourites_count\":86379,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":27444,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"F5F8FA\",\"profile_background_image_url\":null,\"profile_background_image_url_https\":null,\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/1015056769138257923\\/YIMDdGlX_normal.jpg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/1015056769138257923\\/YIMDdGlX_normal.jpg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/816700741339516930\\/1531107483\",\"profile_link_color\":\"1DA1F2\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"is_quote_status\":false,\"retweet_count\":1,\"favorite_count\":1,\"favorited\":false,\"retweeted\":false,\"lang\":\"es\"},\"is_quote_status\":false,\"retweet_count\":1,\"favorite_count\":0,\"favorited\":false,\"retweeted\":false,\"lang\":\"es\"}],\"search_metadata\":{\"completed_in\":0.042,\"max_id\":1023380303648354304,\"max_id_str\":\"1023380303648354304\",\"next_results\":\"?max_id=1023380295473684480&q=Haiti&count=2&include_entities=1\",\"query\":\"Haiti\",\"refresh_url\":\"?since_id=1023380303648354304&q=Haiti&include_entities=1\",\"count\":2,\"since_id\":0,\"since_id_str\":\"0\"}}\n";
    JSONObject jsonObject = new JSONObject(str);
    JSONArray jsonArray = jsonObject.getJSONArray("statuses");
    System.out.println(jsonArray.getJSONObject(0).getString("created_at"));
    System.out.println(jsonArray.getJSONObject(0).getString("text"));

关于java - 如何解析这个 JSONObject 以从 twitter 搜索 API 获取数组内的值来获取每条推文(名称、正文)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51576554/

相关文章:

java - Json响应很慢android

java - 我在将值从 JSON 对象赋值给局部变量时遇到问题,调试器显示变量 = 'this' 不可用

Android AsyncHttpClient - 下载文件时为 "Content-Type not allowed!"

android - 使用 loopj SyncHttpClient 时出现 IOException

java - AsyncHttpClient OnSuccess 或 OnFailure 未被覆盖,但收到回调

java - "Deprecating the Observer Pattern"——其他语言的代码示例?

java - 我可以记录在第 3 方(外部)库中抛出和捕获的异常吗?

JavaFX 2 TextArea 根据其内容改变高度

java - 使用 WebEngine 执行多个脚本(或依赖于另一个脚本的脚本)

android - 如何从 JSONARRAY 中的 JSONOBJECT 获取值?