"{'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'}
无论如何请告诉我。
提前谢谢。
答案 0 :(得分:3)
是的,您可以在jquery
中使用parseJson功能 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(','))
答案 1 :(得分:0)
您可以将此用于转换,但实际上并不知道您在寻找什么。
String.prototype.hashCode = function(){
var hash = 0, i, char;
if (this.length == 0) return hash;
for (i = 0, l = this.length; i < l; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash |= 0; // Convert to 32bit integer
}
return hash;
};