gpt4 book ai didi

ruby - 我如何在 ruby​​ 中解析这个 JSON

转载 作者:太空宇宙 更新时间:2023-11-03 17:29:49 24 4
gpt4 key购买 nike

请帮我用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com