我有以下数据:
"[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]"
我希望它只是:
[{"workstationName":"Test Workstation Id 123"},{"workstationName":"Alex's Workstation"}]
我应该知道这一点。我试过a.to_ary
,但没有好处。有任何直接的处理方式吗?感谢。
答案 0 :(得分:4)
这是怎么回事?
require 'json'
require 'yaml'
JSON.parse("[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]")
# => [{"workstationName"=>"Test Workstation Id 123"},
# {"workstationName"=>"Alex's Workstation"}]
YAML.load("[{\"workstationName\":\"Test Workstation Id 123\"},{\"workstationName\":\"Alex's Workstation\"}]")
# => [{"workstationName"=>"Test Workstation Id 123"},
# {"workstationName"=>"Alex's Workstation"}]
答案 1 :(得分:1)
JSON.parse
正是您要找的