Posted By

eddequincey on 02/17/11


Tagged

javascript json


Versions (?)

Variation on webmonkey tutorial:


 / Published in: JavaScript
 

URL: http://www.webmonkey.com/2010/02/get_started_with_json/

Found that the webmonkey tutorial code didn't work as double quotes were used around JSON string.

  1. <script type="text/javascript">
  2. var moviereviewtext = '{"title": "Friday the 13th", "year": 1980, "reviews": [{"reviewer": "Pam", "stars": 3, "text": "Pretty good, but could have used more Jason"}, {"reviewer": "Alice", "stars": 4, "text": "The end was good, but a little unsettling"}]}';
  3. var jsonobj = eval("(" + moviereviewtext + ")");
  4. var reviewername = jsonobj.reviews[0].reviewer;
  5. var numberstars = jsonobj.reviews[0].stars;
  6. var reviewerthoughts = jsonobj.reviews[0].text;
  7. alert(reviewerthoughts);
  8. </script>

Report this snippet  

You need to login to post a comment.