簡體   English   中英

如何將轉義字符串中的 hash 表示形式轉換為實際的 hash?

[英]How can I convert a hash representation in an escaped string to an actual hash?

我有一個字段存儲在 MySQL 數據庫中,它是一個字符串,但它存儲的是 hash 的表示。 我想知道如何將此字符串轉換為 hash。 我用 gsub 和 JSON.parse 嘗試了一堆不同的東西,但無濟於事。

這是我要轉換的內容的參考:

=> "{:address=>\"\", :city=>\"\", :country=>\"\", :zip=>\"\", :state=>\"\", :industry=>\"\", :org=>\"\", :job_title=>\"\", :purchasing_time_frame=>\"\", :role_in_purchase_process=>\"\", :no_of_employees=>\"\", :comments=>\"\", :custom_questions=>[{\"title\"=>\"License Number\", \"value\"=>\"345g3245\"}, {\"title\"=>\"License Type\", \"value\"=>\"Legal\"}], :create_time=>\"2022-01-17T22:49:26Z\"}" 

提供的字符串不是 JSON,它是一個 hash 的字符串表示形式,可以轉換為 Z0800FC577294C34E0B28AD283943\“5945Z 與eval("{:address=>\"\", :city=>\"\", :country=>\"\", :zip=>\"\", :state=>\"\", :industry=>\"\", :org=>\"\", :job_title=>\"\", :purchasing_time_frame=>\"\", :role_in_purchase_process=>\"\", :no_of_employees=>\"\", :comments=>\"\", :custom_questions=>[{\"title\"=>\"License Number\", \"value\"=>\"345g3245\"}, {\"title\"=>\"License Type\", \"value\"=>\"Legal\"}], :create_time=>\"2022-01-17T22:49:26Z\"}")

善良,這是我的第一個堆棧溢出答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM