Reputation: 35
I need to convert the below string "{'id':1,'name':'Sindhuja','address':'Coimbatore'}" into dictionary in jquery.
Upvotes: 0
Views: 4849
Reputation: 328
var obj = JSON.parse(str.replace(/'/g, '"'));
Just convert it into an Object.
Upvotes: 1
Reputation: 14321
JSON.parse
is built into JavaScript. Additionally, JSON only accepts "
, not '
; so, I added a replace function call.
<script>
di = JSON.parse("{'id':1,'name':'Sindhuja','address':'Coimbatore'}".replace(/'/g,"\""));
console.log(di);
</script>
Upvotes: 2