Saurabh Sharma Saurabh Sharma - 1 year ago 54
Javascript Question

Parsing JSON giving "unexpected token o" error

I am having a problem parsing simple JSON strings. I have checked them on and it shows they are valid. But when I try to parse them using either

or the jQuery alternative it gives me the error "unexpected token o"

<!doctype HTML>

<script type="text/javascript">
var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};
var ques_list = JSON.parse(cur_ques_details);

P.S. I'm encoding my strings using
in PHP.

Answer Source

Your data is already an object. No need to parse it. The javascript interpreter has already parsed it for you.

var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};