jjacquay712 Posted June 18, 2009 Share Posted June 18, 2009 What is the best way to parse JSON from an ajax request? I have heard that using eval() can be insecure. Are the any other ways to do it? If so can you give an example? Thanks, John Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted June 19, 2009 Share Posted June 19, 2009 what do you mean parse JSON?...to get data from it? thats extremely simple...its just like an array in PHP: <script type="text/javascript"> Simple Array: var data = {"key1":"value1", "key2":"value2"}; alert(data['key2']);//will alert "value2" Multi-Dimensional Array var data = {"key1":"value1", "key2":{"key1ofKey2":"value1extended", "key2ofKey2":"value2extended"}}; alert(data['key2']['key1ofKey2']);//will alert "value1extended" </script> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 19, 2009 Share Posted June 19, 2009 Anything JavaScript-related will never be fully secured. Not PHP or anything will be 100% secured. It's fine to use eval IMO. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted June 19, 2009 Share Posted June 19, 2009 Do you mean your ajax call returns a string? you could try json_parse() from json.org Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.