以下是我的 Rstudio 代碼: 代碼:
install.packages("rjson")
library("rjson")
getwd()
result = fromJSON(file = "tweets_no_duplicates_formatted_trying.json")
result$tweet
但是 result$tweet 回傳 null 而不是 tweet,不知道為什么。我怎樣才能得到推文文本,因為推文絕對不是空的。
json檔案:
[
{
"tweet": "xyz",
"created_at": "06-04-2022, 07:49:10",
"entities": {
"hashtags": [
{
"start": 29,
"end": 40,
"tag": "PrayerRoom"
},
{
"start": 41,
"end": 48,
"tag": "auspol"
}
]
},
"source": "Twitter for iPhone",
"public_metrics": {
"retweet_count": 2,
"reply_count": 0,
"like_count": 6,
"quote_count": 0
},
"attachments": null,
"geo": null
}
]
uj5u.com熱心網友回復:
它嵌套更深一層:
str(result)
List of 1
$ :List of 7
..$ tweet : chr "xyz"
..$ created_at : chr "06-04-2022, 07:49:10"
..$ entities :List of 1
.. ..$ hashtags:List of 2
.. .. ..$ :List of 3
.. .. .. ..$ start: num 29
.. .. .. ..$ end : num 40
.. .. .. ..$ tag : chr "PrayerRoom"
.. .. ..$ :List of 3
.. .. .. ..$ start: num 41
.. .. .. ..$ end : num 48
.. .. .. ..$ tag : chr "auspol"
..$ source : chr "Twitter for iPhone"
..$ public_metrics:List of 4
.. ..$ retweet_count: num 2
.. ..$ reply_count : num 0
.. ..$ like_count : num 6
.. ..$ quote_count : num 0
..$ attachments : NULL
..$ geo : NULL
您可以通過首先訪問整個推文來獲取它:
result[[1]]$tweet
[1] "xyz"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/467316.html
