请帮我用 ruby 解析这个 json:
"\"{\\\"Details\\\":[{\\\"WaybillNo\\\":\\\"11-17-657\\\",\\\"ShipperName\\\":\\\"Paritosh Singh\\\",\\\"ShipperAddress\\\":\\\"New Delhi, India\\\",\\\"ShipperMob\\\":\\\"0812944\\\",\\\"ConsigneeName\\\":\\\"SANDY\\\",\\\"ConsigneeAddress\\\":\\\"Mumbai India\\\",\\\"ConsigneeMob\\\":\\\"8355485\\\",\\\"Pieces\\\":\\\"1\\\"}]}\""
谢谢
最佳答案
这看起来像是 JSON 中的 JSON:
require 'json'
string = "\"{\\\"Details\\\":[{\\\"WaybillNo\\\":\\\"11-17-657\\\",\\\"ShipperName\\\":\\\"Paritosh Singh\\\",\\\"ShipperAddress\\\":\\\"New Delhi, India\\\",\\\"ShipperMob\\\":\\\"0812944\\\",\\\"ConsigneeName\\\":\\\"SANDY\\\",\\\"ConsigneeAddress\\\":\\\"Mumbai India\\\",\\\"ConsigneeMob\\\":\\\"8355485\\\",\\\"Pieces\\\":\\\"1\\\"}]}\""
JSON.parse(JSON.parse(string))
#=> {
# "Details" => [
# [0] {
# "WaybillNo" => "11-17-657",
# "ShipperName" => "Paritosh Singh",
# "ShipperAddress" => "New Delhi, India",
# "ShipperMob" => "0812944",
# "ConsigneeName" => "SANDY",
# "ConsigneeAddress" => "Mumbai India",
# "ConsigneeMob" => "8355485",
# "Pieces" => "1"
# }
# ]
# }
关于ruby - 我如何在 ruby 中解析这个 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45061584/