可以jsonlite::fromJSON
用来解析 JSON 文件
基于您的 JSON 示例字符串的示例
ss <- '[{"contributors": null, "truncated": false, "text": "RT @KazmiWajahat: Indian media including @CNNnews18 confirming Pakistans retaliation at LoC forward areas with heavy firing and shelling w\u2026", "is_quote_status": false}]'
library(jsonlite)
fromJSON(ss)
# contributors truncated
#1 NA FALSE
# text
#1 RT @KazmiWajahat: Indian media including @CNNnews18 confirming Pakistans retaliation at LoC forward areas with heavy firing and shelling w…
# is_quote_status
#1 FALSE
由于您提供的样本数据最少,因此您最终data.frame
会得到仅包含一行的数据。
jsonlite
从小插图中举一个稍微复杂一点的例子,
ss <-'[
{"Name" : "Mario", "Age" : 32, "Occupation" : "Plumber"},
{"Name" : "Peach", "Age" : 21, "Occupation" : "Princess"},
{"Name" : "Bowser", "Occupation" : "Koopa"}]'
你可以看到如何fromJSON
解析 JSON 字符串并返回一个data.frame
fromJSON(ss)
# Name Age Occupation
#1 Mario 32 Plumber
#2 Peach 21 Princess
#3 Bowser NA Koopa