2
"{'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'}"

I have this string, I want to convert this into hash in 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'}

Is there anyway Please let me know.

Thank you in advance.

0

2 Answers 2

3

Yes, you can use the parseJson function in 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)

If you having object notations then try

myLoc=jQuery.parseJSON(myLoc.replace(/"/gi,"\"").replace(/\[/gi,"").replace(/\]/gi,"").split(','))
Sign up to request clarification or add additional context in comments.

Comments

0

you can use this for your conversion,but really dont know what you are looking for.

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;
};

1 Comment

This is for prototype javascript but I am using jquery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.