Tuesday, 13 August 2013

JSON.parse produces a syntax error with php's json_encode method

JSON.parse produces a syntax error with php's json_encode method

I have a variable $data['tree'], that gets a row array from the database
using a method, get_tree($id), from the model.
In my view's js I using
var dbTree = JSON.parse(<?php echo $tree; ?>);
When I load the page I get UncaughtSyntax Error: Unexpected token o in
chrome and in firefox I get Syntax Error: Unexpected character.
So When I inspected the script element with chrome the js looked like
var dbTree =
JSON.parse({"id":"2","name":"sean","userId":"51fbd3f3a8f2ba1b5b000002","accountId":"51fbd3fca8f2ba1b5b000003","createdAt":"2013-08-02
16:09:34","numRuns":null,"contactExport":"","updatedAt":"2013-08-02
20:15:14","deployed":"1","template":"0","conversation_type":"Conversation"});
I don't see anything wrong with that can some help me out.

No comments:

Post a Comment