Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php var_dump($myArray); ?>
  2.  
  3. array (size=4)
  4. 'id' => string '162' (length=3)
  5. 'content' => string 'Test content' (length=12)
  6. 'children' =>
  7. array (size=16)
  8. 0 =>
  9. array (size=4)
  10. 'id' => string '29208' (length=5)
  11. 'content' => string 'Test content 1' (length=14)
  12. 'children' =>
  13. array (size=3)
  14. ...
  15. 1 =>
  16. array (size=4)
  17. 'id' => string '29215' (length=5)
  18. 'content' => string 'Test content 2' (length=14)
  19. 'children' =>
  20. array (size=1)
  21. ...
  22. 2 =>
  23. array (size=3)
  24. 'id' => string '29220' (length=5)
  25. 'content' => string 'Test Content 3' (length=14)
  26.  
  27. <script type="text/javascript">
  28. var myVar = JSON.parse('<?php json_encode($myArray) ?>');
  29. </script>
  30.  
  31. Uncaught SyntaxError: Unexpected end of input
  32.  
  33. <script type="text/javascript">
  34. var x = '{"id":123,"content":"This is a test content"}';
  35. var myVar = JSON.parse(x);
  36. console.log(myVar);
  37. </script>
  38.  
  39. Object
  40. content: "This is a test content"
  41. id: 123
  42.  
  43. <?php json_encode($myArray) ?>
  44.  
  45. <?php echo json_encode($myArray) ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement