如何在R

时间:2016-02-22 05:50:49

标签: r

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

  1. { “颜色”: “黑”, “尺寸”: “”, “材料”: “乔其纱”, “场合”: “方”, “上升”: “”, “长度”: “”,”图案 “:” 绣花”, “套”: “”, “neck_type”: “”, “适合”: “”, “bra_type”: “”, “布线”: “”, “color_filter”: “黑”, “type_filter”: “半缝合”, “性别”: “女性”, “designed_by”: “”, “article_identifier_type”: “”, “article_identification_value”: “”, “product_dimension”: “”}
  2. 2 { “颜色”: “蓝”, “大小”: “”, “材料”: “乔其纱”, “场合”: “方”, “上升”: “”, “长度”: “” “图案”: “绣花”, “套”: “”, “neck_type”: “”, “适合”: “”, “bra_type”: “”, “布线”: “”, “color_filter”:“蓝”, “type_filter”: “半缝合”, “性别”: “女性”, “designed_by”: “”, “article_identifier_type”: “”, “article_identification_value”: “”, “product_dimension”: “”}

    3 { “颜色”: “白”, “尺寸”: “”, “材料”: “棉”, “场合”: “民族”, “上升”: “”, “长度”: “” “图案”: “绣花”, “套”: “”, “neck_type”: “”, “适合”: “”, “bra_type”: “”, “布线”: “”, “color_filter”:“白“,”type_filter“:”With Blouse“,”gender“:”Women“,”designed_by“:”“,”article_identifier_type“:”“,”article_identification_value“:”“,”product_dimension“:”“}

    4。 { “颜色”: “蓝”, “大小”: “”, “材料”: “乔其纱”, “场合”: “方”, “上升”: “”, “长度”: “”, “图案”: “绣花”, “套”: “”, “neck_type”: “”, “适合”: “”, “bra_type”: “”, “布线”: “”, “color_filter”: “蓝”, “type_filter” : “半缝合”, “性别”: “女性”, “designed_by”: “”, “article_identifier_type”: “”, “article_identification_value”: “”, “product_dimension”: “”}

    5 { “颜色”: “绿松石”, “大小”: “”, “材料”: “棉”, “场合”: “方”, “上升”: “”, “长度”: “” ,“pattern”:“Floral Print”,“sleeve”:“”,“neck_type”:“”,“fit”:“”,“bra_type”:“”,“wiring”:“”,“color_filter”:“绿松石”, “type_filter”: “半缝合”, “性别”: “女性”, “designed_by”: “”, “article_identifier_type”: “”, “article_identification_value”: “”, “product_dimension”: “”} < / p>

1 个答案:

答案 0 :(得分:0)

考虑到此文件的格式是以分号分隔的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))

我希望这会对你有所帮助