如何在R中读取JSON字符串的CSV

韦巴哈·塔库尔

我有一个文件,其中的行包含不同的JSON字符串,此文件的格式为CSV,我想将所有这些JSON字符串导入R中,但无法找到成功的方法,我想避免将CSV转换为的解决方案首先是JSON。

  1. {“颜色”:“黑色”,“尺寸”:“”,“材料”:“乔其纱”,“场合”:“派对”,“上升”:“”,“长度”:“”,“样式”: “ Embroidered”,“ sleeve”:“”,“ neck_type”:“”,“ fit”:“”,“ bra_type”:“”,“ wiring”:“”,“ color_filter”:“ Black”,“ type_filter” :“半缝制”,“性别”:“妇女”,“ designed_by”:“”,“ article_identifier_type”:“”,“ article_identification_value”:“”,“ product_dimension”:“”}

2. {“颜色”:“蓝色”,“尺寸”:“”,“材料”:“乔其”,“场合”:“派对”,“上升”:“”,“长度”:“”,“图案“:”绣“,”袖“:”“,” neck_type“:”“,” fit“:”“,” bra_type“:”“,”接线“:”“,” color_filter“:”蓝色“,” type_filter“:”半缝合“,”性别“:”妇女“,” designedby“:”“,” article_identifier_type“:”“,” article_identification_value“:”“,” product_dimension“:”“}

3. {“颜色”:“白色”,“尺寸”:“”,“材料”:“棉布”,“场合”:“民族”,“上升”:“”,“长度”:“”,“图案“:”绣“,”袖“:”“,” neck_type“:”“,” fit“:”“,” bra_type“:”“,”接线“:”“,” color_filter“:”白色“,” type_filter“:”带上衣“,” gender“:”妇女“,” designed_by“:”“,” article_identifier_type“:”“,” article_identification_value“:”“,” product_dimension“:”“}

4. {“颜色”:“蓝色”,“尺寸”:“”,“材料”:“乔其纱”,“场合”:“派对”,“上升”:“”,“长度”:“”,“样式” “:”绣“,”袖“:”“,” neck_type“:”“,” fit“:”“,” bra_type“:”“,”接线“:”“,” color_filter“:”蓝色“,” type_filter“:”半缝合“,”性别“:”妇女“,” designedby“:”“,” article_identifier_type“:”“,” article_identification_value“:”“,” product_dimension“:”“}

5。{“ color”:“ Turquoise”,“ size”:“”,“ material”:“棉布”,“场合”:“ Party”,“ rise”:“”,“ length”:“”,“ pattern “:”花卉印花“,”袖“:”“,” neck_type“:”“,” fit“:”“,” bra_type“:”“,”接线“:”“,” color_filter“:”绿松石“, “ type_filter”:“半缝制”,“ gender”:“妇女”,“ designed_by”:“”,“ article_identifier_type”:“”,“ article_identification_value”:“”,“ product_dimension”:“”}

吉查德

考虑到此文件的格式是用分号分隔的CSV,这可能是可行的:

require(jsonlite)


# Importing CSV 
my_data <- read.csv2("data.csv", sep = ";", header = F, stringsAsFactors = F, quote = "") #keep quotes


# Transform JSON into a list
my_data.list <- lapply(my_data$V1, function(x) fromJSON(x))


# Transform into DF
my_data.df <- do.call("rbind", lapply(my_data.list, as.data.frame))

我希望这能帮到您

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章