2011-12-09 12 views
0

JSONとして解析してポストリクエストとして送信するには、次の文字列があります。json形式の文字列を解析する必要があります

スタート= 0 & page_length = 50 & exclude_vehicle_category =%5B%5D & toll_non_toll = falseを&モード=%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%22%%22%2C%20%22snap_direction%22%3A%20%22beginning%22% 7D & end_date =%7B%7D & time_zone =%22EST%22 カラム=%5B%22GROUPNAME%22%2C%20%22VEHICLEID%22%2C%20%22VEHICLENAME%22%2C%20%22VEHICLETAG%22%2C %20%22VEHICLE_VIN%22%2C%20%22T OTAL_DISTANCE_DRIVEN%22%2C%20%22TOTAL_DISTANCE_DRIVEN_OH%22%5D &%5B%5D &ソート=%5B%5B%22GROUPNAME%22%2C%20%%5D%2C%20%5B%22VEHICLEID%22%2C% 20false%の5D%5D

答えて

2

セイsはあなたの文字列が含まれています

hash = {} 
s.split("&").each do |key_value| 
    key, value = key_value.split("=") 
    hash[key.to_sym] = value 
end 
hash.to_json 
0
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]]" 
    } 
関連する問題