【问题标题】:How to split this crazy string? [duplicate]如何拆分这个疯狂的字符串? [复制]
【发布时间】:2019-03-27 17:46:41
【问题描述】:
Current Data


Sr. Genres
1   [{"id": 28, "name": "Action"}, {"id": 12, "name": "Adventure"}, {"id": 14, "name": "Fantasy"}, {"id": 878, "name": "Science Fiction"}]
2   [{"id": 12, "name": "Adventure"}, {"id": 14, "name": "Fantasy"}, {"id": 28, "name": "Action"}]
3   [{"id": 28, "name": "Action"}, {"id": 12, "name": "Adventure"}, {"id": 80, "name": "Crime"}]
4   [{"id": 28, "name": "Action"}, {"id": 80, "name": "Crime"}, {"id": 18, "name": "Drama"}, {"id": 53, "name": "Thriller"}]
5   [{"id": 28, "name": "Action"}, {"id": 12, "name": "Adventure"}, {"id": 878, "name": "Science Fiction"}]

需要的输出

Sr. id  name    id  name    id  name    id  name
1   28  Action  12  Adventure   14  Fantasy 878 Science Fiction
2   12  Adventure   14  Fantasy 28  Action      
3   28  Action  12  Adventure   80  Crime   53  Thriller
4   28  Action  80  Crime   18  Drama       
5   28  Action  12  Adventure   878 Science Fiction     

任何帮助如何做到这一点?

【问题讨论】:

标签: r


【解决方案1】:

只需使用 RJSON 包。 ...

#First install JSON Package:
install.packages("rjson")

# Load the package to your workspace
library(rjson)

# read your input file, assuming this is called input.json
result <- fromJSON(file = "input.json")

# Print the result.
out <- as.data.frame(result)

# Then export it
write.table(out,file="out.txt",sep="\t",col.names=T,row.names=F)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 2017-08-21
    • 2011-03-03
    • 2017-03-24
    • 1970-01-01
    相关资源
    最近更新 更多