首页 > 解决方案 > 将 JSON 导出到文本文件

问题描述

无法将 json 字符串导出到文本文件 -

> tester <- list(10, 20) %>% 
          toJSON(. , auto_unbox = T)
> write.table(tester, file = "JSONfile.txt", sep = "")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""json"" to a data.frame

是否有将 JSON 导出为文本的替代方法?

标签: rjson

解决方案


也许试试

sink("./JSONfile.txt")
list(10, 20) %>% toJSON(. , auto_unbox = T) %>% cat
sink()

推荐阅读