Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json: how to get the json-string into a javascript object

i am converting my ajax code from xml to json, but i am missing something basic here:

when i receive the json-string on the client-side, what is the recommended way to convert it into a javascript object.

for example i get this string:

{"connectionid":12345}

and i would like to do something like this:

alert(xmlhttp.responseText.connectionid);

thanks!

like image 238
clamp Avatar asked Jan 27 '26 20:01

clamp


1 Answers

Use JSON.parse(), or eval(), if you like to live dangerously (or fully trust where your JSON comes from).

If you happen to be using jQuery, you get $.parseJSON().

like image 77
alex Avatar answered Jan 29 '26 08:01

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!