需要将字符串解析为json格式

发布于 2024-12-20 14:19:15 字数 738 浏览 2 评论 0原文

我有以下字符串解析为 JSON 并作为 post 请求发送。不确定执行此操作的最佳方法是什么:

开始=0&page_length=50&exclude_vehicle_category=%5B%5D&toll_non_toll=false&mode=%22detail_state_mileage_report%22&scope_kind=%22enterprise_group%22& ;scope_value=4317&scope_values=%7B%22enterprise_group%22%3A%204317%7D&start_date=%7B%22snap_unit%22%3A%20%22day%22%2C%20%22snap_direction%22%3A%20%22开始%22%7 D&end_date=%7B%7D&time_zone=%22EST%22&columns=%5B%22GROUPNAME%22%2C%20%22 VEHICLEID%22%2C%20%22VEHICLENAME%22%2C%20%22VEHICLETAG%22%2C%20%22VEHICLE_VIN%22%2C%20 %22TOTAL_DISTANCE_DRIVEN%22%2C%20%22TOTAL_DISTANCE_DRIVEN_OH%22%5D&着色=%5B%5D &sort=%5B%5B%22GROUPNAME%22%2C%20false%5D%2C%20%5B%22VEHICLEID%22%2C%20false%5D%5D

i have this following string to parse as JSON and send as post request. not sure what is the best way to do this:

start=0&page_length=50&exclude_vehicle_category=%5B%5D&toll_non_toll=false&mode=%22detail_state_mileage_report%22&scope_kind=%22enterprise_group%22&scope_value=4317&scope_values=%7B%22enterprise_group%22%3A%204317%7D&start_date=%7B%22snap_unit%22%3A%20%22day%22%2C%20%22snap_direction%22%3A%20%22beginning%22%7D&end_date=%7B%7D&time_zone=%22EST%22&columns=%5B%22GROUPNAME%22%2C%20%22VEHICLEID%22%2C%20%22VEHICLENAME%22%2C%20%22VEHICLETAG%22%2C%20%22VEHICLE_VIN%22%2C%20%22TOTAL_DISTANCE_DRIVEN%22%2C%20%22TOTAL_DISTANCE_DRIVEN_OH%22%5D&coloring=%5B%5D&sort=%5B%5B%22GROUPNAME%22%2C%20false%5D%2C%20%5B%22VEHICLEID%22%2C%20false%5D%5D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幼儿园老大 2024-12-27 14:19:15

假设 s 包含您的字符串:

hash = {}   
s.split("&").each do |key_value|
  key, value = key_value.split("=")
  hash[key.to_sym] = value
end
hash.to_json

Say s contains your string:

hash = {}   
s.split("&").each do |key_value|
  key, value = key_value.split("=")
  hash[key.to_sym] = value
end
hash.to_json
王权女流氓 2024-12-27 14:19:15
Rack::Utils.parse_query(s)
=> {"start"=>"0",
    "page_length"=>"50",
    "exclude_vehicle_category"=>"[]",
    "toll_non_toll"=>"false",
    "mode"=>"\"detail_state_mileage_report\"",
    "scope_kind"=>"\"enterprise_group\"",
    "scope_value"=>"4317",
    "scope_values"=>"{\"enterprise_group\": 4317}",
    "start_date"=>"{\"snap_unit\": \"day\", \"snap_direction\": \"beginning\"}",
    "end_date"=>"{}",
    "time_zone"=>"\"EST\"",
    "columns"=>"[\"GROUPNAME\", \"VEHICLEID\", \"VEHICLENAME\", \"VEHICLETAG\", \"VEHICLE_VIN\", \"TOTAL_DISTANCE_DRIVEN\", \"TOTAL_DISTANCE_DRIVEN_OH\"]",
    "coloring"=>"[]",
    "sort"=>"[[\"GROUPNAME\", false],[\"VEHICLEID\", false]]"
   } 
Rack::Utils.parse_query(s)
=> {"start"=>"0",
    "page_length"=>"50",
    "exclude_vehicle_category"=>"[]",
    "toll_non_toll"=>"false",
    "mode"=>"\"detail_state_mileage_report\"",
    "scope_kind"=>"\"enterprise_group\"",
    "scope_value"=>"4317",
    "scope_values"=>"{\"enterprise_group\": 4317}",
    "start_date"=>"{\"snap_unit\": \"day\", \"snap_direction\": \"beginning\"}",
    "end_date"=>"{}",
    "time_zone"=>"\"EST\"",
    "columns"=>"[\"GROUPNAME\", \"VEHICLEID\", \"VEHICLENAME\", \"VEHICLETAG\", \"VEHICLE_VIN\", \"TOTAL_DISTANCE_DRIVEN\", \"TOTAL_DISTANCE_DRIVEN_OH\"]",
    "coloring"=>"[]",
    "sort"=>"[[\"GROUPNAME\", false],[\"VEHICLEID\", false]]"
   } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文