我有一个包含以 JSON 格式存储的推文的文本文件。
"{\"contributors\":null,\"coordinates\":null,\"in_reply_to_user_id\":null,\"truncated\":false,\"text\":\"I find wrapping myself up in my rug more fun than I should.\",\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[]},\"place\":null,\"id_str\":\"234702954832220160\",\"favorited\":false,\"geo\":null,\"source\":\"\u003Ca href=\\"http:\/\/blackberry.com\/twitter\\" rel=\\"nofollow\\"\u003ETwitter for BlackBerry\u00ae\u003C\/a\u003E\",\"retweet_count\":0,\"in_reply_to_status_id_str\":null,\"in_reply_to_screen_name\":null,\"created_at\":\"Sun Aug 12 17:28:39 +0000 2012\",\"in_reply_to_user_id_str\":null,\"user\":{\"show_all_inline_media\":true,\"lang\":\"en\",\"friends_count\":200,\"profile_sidebar_border_color\":\"BDDCAD\",\"location\":\"Newcastle\",\"profile_background_image_url_https\":\"https:\/\/si0.twimg.com\/profile_background_images\/613341681\/ed47iwy7apcu7nltbj1y.jpeg\",\"id_str\":\"369637639\",\"listed_count\":0,\"profile_use_background_image\":true,\"profile_image_url_https\":\"https:\/\/si0.twimg.com\/profile_images\/2459865521\/photo_653_normal.jpg\",\"description\":\"Hi, I'm Ellen, but you've probably guessed that by now. You can follow me but I don't know where I'm going.\",\"follow_request_sent\":null,\"following\":null,\"profile_text_color\":\"333333\",\"default_profile\":false,\"profile_background_image_url\":\"http:\/\/a0.twimg.com\/profile_background_images\/613341681\/ed47iwy7apcu7nltbj1y.jpeg\",\"followers_count\":335,\"is_translator\":false,\"time_zone\":\"London\",\"profile_link_color\":\"0084B4\",\"protected\":false,\"created_at\":\"Wed Sep 07 17:56:39 +0000 2011\",\"profile_background_color\":\"9AE4E8\",\"name\":\"ellen\u2020urnbull \",\"default_profile_image\":false,\"contributors_enabled\":false,\"statuses_count\":788,\"geo_enabled\":false,\"notifications\":null,\"profile_background_tile\":false,\"url\":null,\"profile_image_url\":\"http:\/\/a0.twimg.com\/profile_images\/2459865521\/photo_653_normal.jpg\",\"screen_name\":\"ellenteee\",\"id\":369637639,\"verified\":false,\"utc_offset\":0,\"favourites_count\":10,\"profile_sidebar_fill_color\":\"DDFFCC\"},\"retweeted\":false,\"in_reply_to_status_id\":null,\"id\":234702954832220160}
"
"{\"contributors\":null,\"coordinates\":null,\"in_reply_to_user_id\":null,\"truncated\":false,\"text\":\"Goodevening!\",\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[]},\"place\":null,\"id_str\":\"234702954828029952\",\"favorited\":false,\"geo\":null,\"source\":\"\u003Ca href=\\"http:\/\/twitter.com\/download\/android\\" rel=\\"nofollow\\"\u003ETwitter for Android\u003C\/a\u003E\",\"retweet_count\":0,\"in_reply_to_status_id_str\":null,\"in_reply_to_screen_name\":null,\"created_at\":\"Sun Aug 12 17:28:39 +0000 2012\",\"in_reply_to_user_id_str\":null,\"user\":{\"show_all_inline_media\":true,\"lang\":\"en\",\"friends_count\":130,\"profile_sidebar_border_color\":\"D3D2CF\",\"location\":\"#3block,St. Rose \",\"profile_background_image_url_https\":\"https:\/\/si0.twimg.com\/profile_background_images\/341819936\/Tyga.jpg\",\"id_str\":\"331869167\",\"listed_count\":0,\"profile_use_background_image\":true,\"profile_image_url_https\":\"https:\/\/si0.twimg.com\/sticky\/default_profile_images\/default_profile_0_normal.png\",\"description\":\" R.I.P Mealey you will be truly miss. Gone but never forgotten. #teamGod #HeatNation\",\"follow_request_sent\":null,\"following\":null,\"profile_text_color\":\"634047\",\"default_profile\":false,\"profile_background_image_url\":\"http:\/\/a0.twimg.com\/profile_background_images\/341819936\/Tyga.jpg\",\"followers_count\":100,\"is_translator\":false,\"time_zone\":\"Central Time (US & Canada)\",\"profile_link_color\":\"088253\",\"protected\":false,\"created_at\":\"Fri Jul 08 21:06:02 +0000 2011\",\"profile_background_color\":\"EDECE9\",\"name\":\"T\u00e9 lu\u00f2 y\u012b \",\"default_profile_image\":true,\"contributors_enabled\":false,\"statuses_count\":16944,\"geo_enabled\":false,\"notifications\":null,\"profile_background_tile\":false,\"url\":null,\"profile_image_url\":\"http:\/\/a0.twimg.com\/sticky\/default_profile_images\/default_profile_0_normal.png\",\"screen_name\":\"Troy_rollupone\",\"id\":331869167,\"verified\":false,\"utc_offset\":-21600,\"favourites_count\":41,\"profile_sidebar_fill_color\":\"E3E2DE\"},\"retweeted\":false,\"in_reply_to_status_id\":null,\"id\":234702954828029952}
"
我使用以下方法扫描文件:
> twit <- scan("twitCapture2.txt","",sep="\n")
Read 4 items
> twit
[1] "\"{\\\"contributors\\\":null,\\\"coordinates\\\":null,\\\"in_reply_to_user_id\\\":null,\\\"truncated\\\":false,\\\"text\\\":\\\"I find wrapping myself up in my rug more fun than I should.\\\",\\\"entities\\\":{\\\"hashtags\\\":[],\\\"urls\\\":[],\\\"user_mentions\\\":[]},\\\"place\\\":null,\\\"id_str\\\":\\\"234702954832220160\\\",\\\"favorited\\\":false,\\\"geo\\\":null,\\\"source\\\":\\\"\\u003Ca href=\\\\\"http:\\/\\/blackberry.com\\/twitter\\\\\" rel=\\\\\"nofollow\\\\\"\\u003ETwitter for BlackBerry\\u00ae\\u003C\\/a\\u003E\\\",\\\"retweet_count\\\":0,\\\"in_reply_to_status_id_str\\\":null,\\\"in_reply_to_screen_name\\\":null,\\\"created_at\\\":\\\"Sun Aug 12 17:28:39 +0000 2012\\\",\\\"in_reply_to_user_id_str\\\":null,\\\"user\\\":{\\\"show_all_inline_media\\\":true,\\\"lang\\\":\\\"en\\\",\\\"friends_count\\\":200,\\\"profile_sidebar_border_color\\\":\\\"BDDCAD\\\",\\\"location\\\":\\\"Newcastle\\\",\\\"profile_background_image_url_https\\\":\\\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/613341681\\/ed47iwy7apcu7nltbj1y.jpeg\\\",\\\"id_str\\\":\\\"369637639\\\",\\\"listed_count\\\":0,\\\"profile_use_background_image\\\":true,\\\"profile_image_url_https\\\":\\\"https:\\/\\/si0.twimg.com\\/profile_images\\/2459865521\\/photo_653_normal.jpg\\\",\\\"description\\\":\\\"Hi, I'm Ellen, but you've probably guessed that by now. You can follow me but I don't know where I'm going.\\\",\\\"follow_request_sent\\\":null,\\\"following\\\":null,\\\"profile_text_color\\\":\\\"333333\\\",\\\"default_profile\\\":false,\\\"profile_background_image_url\\\":\\\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/613341681\\/ed47iwy7apcu7nltbj1y.jpeg\\\",\\\"followers_count\\\":335,\\\"is_translator\\\":false,\\\"time_zone\\\":\\\"London\\\",\\\"profile_link_color\\\":\\\"0084B4\\\",\\\"protected\\\":false,\\\"created_at\\\":\\\"Wed Sep 07 17:56:39 +0000 2011\\\",\\\"profile_background_color\\\":\\\"9AE4E8\\\",\\\"name\\\":\\\"ellen\\u2020urnbull \\\",\\\"default_profile_image\\\":false,\\\"contributors_enabled\\\":false,\\\"statuses_count\\\":788,\\\"geo_enabled\\\":false,\\\"notifications\\\":null,\\\"profile_background_tile\\\":false,\\\"url\\\":null,\\\"profile_image_url\\\":\\\"http:\\/\\/a0.twimg.com\\/profile_images\\/2459865521\\/photo_653_normal.jpg\\\",\\\"screen_name\\\":\\\"ellenteee\\\",\\\"id\\\":369637639,\\\"verified\\\":false,\\\"utc_offset\\\":0,\\\"favourites_count\\\":10,\\\"profile_sidebar_fill_color\\\":\\\"DDFFCC\\\"},\\\"retweeted\\\":false,\\\"in_reply_to_status_id\\\":null,\\\"id\\\":234702954832220160}"
[2] "\""
[3] "\"{\\\"contributors\\\":null,\\\"coordinates\\\":null,\\\"in_reply_to_user_id\\\":null,\\\"truncated\\\":false,\\\"text\\\":\\\"Goodevening!\\\",\\\"entities\\\":{\\\"hashtags\\\":[],\\\"urls\\\":[],\\\"user_mentions\\\":[]},\\\"place\\\":null,\\\"id_str\\\":\\\"234702954828029952\\\",\\\"favorited\\\":false,\\\"geo\\\":null,\\\"source\\\":\\\"\\u003Ca href=\\\\\"http:\\/\\/twitter.com\\/download\\/android\\\\\" rel=\\\\\"nofollow\\\\\"\\u003ETwitter for Android\\u003C\\/a\\u003E\\\",\\\"retweet_count\\\":0,\\\"in_reply_to_status_id_str\\\":null,\\\"in_reply_to_screen_name\\\":null,\\\"created_at\\\":\\\"Sun Aug 12 17:28:39 +0000 2012\\\",\\\"in_reply_to_user_id_str\\\":null,\\\"user\\\":{\\\"show_all_inline_media\\\":true,\\\"lang\\\":\\\"en\\\",\\\"friends_count\\\":130,\\\"profile_sidebar_border_color\\\":\\\"D3D2CF\\\",\\\"location\\\":\\\"#3block,St. Rose \\\",\\\"profile_background_image_url_https\\\":\\\"https:\\/\\/si0.twimg.com\\/profile_background_images\\/341819936\\/Tyga.jpg\\\",\\\"id_str\\\":\\\"331869167\\\",\\\"listed_count\\\":0,\\\"profile_use_background_image\\\":true,\\\"profile_image_url_https\\\":\\\"https:\\/\\/si0.twimg.com\\/sticky\\/default_profile_images\\/default_profile_0_normal.png\\\",\\\"description\\\":\\\" R.I.P Mealey you will be truly miss. Gone but never forgotten. #teamGod #HeatNation\\\",\\\"follow_request_sent\\\":null,\\\"following\\\":null,\\\"profile_text_color\\\":\\\"634047\\\",\\\"default_profile\\\":false,\\\"profile_background_image_url\\\":\\\"http:\\/\\/a0.twimg.com\\/profile_background_images\\/341819936\\/Tyga.jpg\\\",\\\"followers_count\\\":100,\\\"is_translator\\\":false,\\\"time_zone\\\":\\\"Central Time (US & Canada)\\\",\\\"profile_link_color\\\":\\\"088253\\\",\\\"protected\\\":false,\\\"created_at\\\":\\\"Fri Jul 08 21:06:02 +0000 2011\\\",\\\"profile_background_color\\\":\\\"EDECE9\\\",\\\"name\\\":\\\"T\\u00e9 lu\\u00f2 y\\u012b \\\",\\\"default_profile_image\\\":true,\\\"contributors_enabled\\\":false,\\\"statuses_count\\\":16944,\\\"geo_enabled\\\":false,\\\"notifications\\\":null,\\\"profile_background_tile\\\":false,\\\"url\\\":null,\\\"profile_image_url\\\":\\\"http:\\/\\/a0.twimg.com\\/sticky\\/default_profile_images\\/default_profile_0_normal.png\\\",\\\"screen_name\\\":\\\"Troy_rollupone\\\",\\\"id\\\":331869167,\\\"verified\\\":false,\\\"utc_offset\\\":-21600,\\\"favourites_count\\\":41,\\\"profile_sidebar_fill_color\\\":\\\"E3E2DE\\\"},\\\"retweeted\\\":false,\\\"in_reply_to_status_id\\\":null,\\\"id\\\":234702954828029952}"
[4] "\""
>
然后,当我尝试使用时fromJSON
,出现以下错误:
> library(RJSONIO)
>
> twit1<-fromJSON(twit1)
Error in file(con, "r") : invalid 'description' argument
> twit1<-fromJSON(twit1[1])
Error in file(con, "r") : cannot open the connection
> f <- RJSONIO::fromJSON(toJSON(twit1[3]))
> f$text
Error in f$text : $ operator is invalid for atomic vectors
> f <- rjson::fromJSON(toJSON(twit1[3]))
> f$text
Error in f$text : $ operator is invalid for atomic vectors
>
关于我做错了什么的任何想法?