'Long Island sound','primary_btm_or_ee_' => '210','primary_btm_or_ee_' => '-6ren">
gpt4 book ai didi

jquery - 我需要在 jquery/javascript 中将字符串转换为哈希

转载 作者:行者123 更新时间:2023-12-01 03:40:10 25 4
gpt4 key购买 nike

"{'long_island_sound' => 'Long Island sound','primary_btm_or_ee_' => '210','primary_btm_or_ee_' => '211','primary_btm_or_ee_' => '370','primary_btm_or_ee_' => '372'}"

我有这个字符串,我想在 Jquery/Javascript 中将其转换为哈希值。

{'long_island_sound' => 'Long Island sound','primary_btm_or_ee_' => '210','primary_btm_or_ee_' => '211','primary_btm_or_ee_' => '370','primary_btm_or_ee_' => '372'}

有吗请告诉我。

提前谢谢您。

最佳答案

是的,您可以使用parseJson jquery中的函数

    var myLoc="{'long_island_sound' => 'Long Island sound','primary_btm_or_ee_' => '210','primary_btm_or_ee_' => '211','primary_btm_or_ee_' => '370','primary_btm_or_ee_' => '372'}"
myLoc=jQuery.parseJSON(myLoc)

如果您有对象符号,请尝试

myLoc=jQuery.parseJSON(myLoc.replace(/"/gi,"\"").replace(/\[/gi,"").replace(/\]/gi,"").split(','))

关于jquery - 我需要在 jquery/javascript 中将字符串转换为哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22601780/

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