【发布时间】:2015-09-19 03:46:06
【问题描述】:
我想创建一个 JSON 格式的数据
{"Recipe Name": "ABC",
"Main Ingredient": "xyz",
"Ingredients": {type:"a"
id:"1"},
{type:"b"
id:"2"},
{type:"b"
id:"3"}
"Servings": 3,}
我有一个类型的数据框:
Recipe, Recipe Id ,Ingredients,Ingredients ID,Servings ,Main Ingredient,Main Ingredient ID
"abc" , 2 , {"a","b","c"} , {1,2,3,} , 5 , "f" ,7
"bcf" , 3 , {"d","e","f"} , {4,5,7} , 4 ,"g" ,8
....
我尝试了 usign rjson 包,但得到了 character(0) 作为输出。有人可以帮我解决这个问题吗?
我确实找到了一种方法
>library(RJSONIO)
>toJSON(dataframe)
这是输出:
[1] "{\n \"factor1\": [ \"115g\", \"1\", null, null ],\n\"unit1\": [ \"tub\", \ "cups\", \"希腊语\", \"baby\" ],\n\"item1\": [ \"tomatoes NA\", \"kalamata Olives\", \"feta cheese\", \"火箭 NA\" ] \n}"
不符合要求的格式
【问题讨论】:
-
您的 data.frame 中是否确实存储了字符串
{"d","e","f"}?如果您提供 reproducible example (如果您的输入数据框可能会提供dput()以明确您正在使用的内容)会有所帮助。你尝试运行什么代码给你character(0)? -
R 数据框中的
Main Ingredient替代品在哪里? -
@MrFlick 是的,我的数据框中有这些刺痛。你能帮帮我吗?