[英]How do I parse the results from a JSON output into a data frame?
In trying to analyze tweets from a hashtag, I am able to obtain 100 results at a time via this call. 在尝试从主题标签分析推文时,我可以通过此调用一次获得100个结果。
curl -i "http://otter.topsy.com/search.json?q=esa2012&window=a&perpage=100&offset=0" >> esa2012_0.json
resulting in a file like this (JSON file in link). 导致像文件这样 (在链接JSON文件)。
How do I read this into R
and convert it to a data.frame
? 如何将其读入
R
并将其转换为data.frame
?
Thus far I am able to skip the first several (non-JSON) lines like so: 到目前为止,我能够跳过前几个(非JSON)行,如下所示:
library(XML)
library(RJSONIO)
file0 <- scan(file = "~/Desktop/data/esa2012_0.json", skip = 18, what= "raw")
but the resulting read becomes difficult to coerce. 但由此产生的阅读变得难以胁迫。
fromJSON(file0)
should do it. fromJSON(file0)
应该这样做。
I typically run it with ,simplify=FALSE
and construct the data.frame myself rather than trying to have it simplify for me. 我通常使用
,simplify=FALSE
运行它并自己构造data.frame,而不是试图让它简化。
Note you don't need the command line call to curl
if you use the RCurl library: 请注意,如果使用RCurl库,则不需要命令行调用
curl
:
library(RJSONIO)
library(RCurl)
j <- getURL("http://blah?mine=yours")
fromJSON(j)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.