从字符串中删除元素+将其转换为数组

时间:2016-08-08 10:05:42

标签: arrays ruby string

我有这个字符串: data = "[\"super\", \"cool!\", \"bien écrit\", \"first!\", \"why is everyone speaking French here?\"]"

我想将其转换为: data = ["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"]

2 个答案:

答案 0 :(得分:3)

将其解析为JSON。尝试

require 'json'
data = JSON.parse data

答案 1 :(得分:1)

数据看起来像JSON。使用JSON.parse(data)

解析它