问题描述
library(jsonlite)
test <- read_csv("6_items.csv")
jsoncars <- toJSON(test,pretty=TRUE)
View(jsoncars)
write_json(jsoncars,"6_items.json" )
需要更改哪些参数?怎么样?
谢谢
CSV 文件
“Year”、“Names”、“Size”、“Volume”、“AchsenMax”、“AchsenMid”、“AchsenMin”、“Class”、“Parts” 2001,"Category1",72,25,36,"Segment",6 2004,"Category2",41,40,6 2009,35,6 2010,"Category3",66,52,6 2013,"类别1",45,17,"细分",6 2016,38,6
解决方法
使用fun numToString(value: Int,res: Resources): String = res.getString(getResourceKey(value))
fun getResourceKey(value: Int): String = when(value) {
1 -> R.string.first
2 -> R.string.second
3 -> R.string.third
4 -> R.string.fourth
else -> R.string.fifth
}
:
cat
json 文件中是这样的。
用您的数据 (cat(jsonlite::toJSON(mtcars,pretty=TRUE),file = 'temp.json')
) 替换 mtcars
。
使用 .csv 文件和/或一些代码来重复错误会很有帮助。不过,看起来有很多空格(/n),你可以试试;
library(jsonlite)
test <- read_csv("6_items.csv")
test <- trimws(test)
jsoncars <- toJSON(test,pretty=TRUE)
View(jsoncars)
write_json(jsoncars,"6_items.json" )