javascript - parseJSON working in one case and not in other -


i fetching json data server using ajay passing array json_enocode() of php, returned json valid(checked on many online json debugger). $.parsejson() of js not accepting it. parser throwing error(below) 1 set of data while works other set of data.

console> syntaxerror: json.parse: unexpected character @ line 1 column 1 of json data

i tried removing elements of array 1 one not working single element. here data sets:

this working:

[{"id":"54a3b103877c0","act_name":"abc","profile_image":"[\"551d\"]"}] 

while not:

[{"id":"2","user_id":"53b595a","review_for_id":"54f25","review_for_type":"city", "r_title":"asfasas asd as","r_body":"a sdasda sdas dasdas das d","r_rating":"3", "other_info":"","added":"2015-03-28 15:47:20","modified":"2015-03-28 15:47:20", "f_name":"abc","l_name":"xyz","lives_in":"abc"}] 

php code:

array:

array ( [0] => array     (         [id] => 2         [user_id] => 53b595a         [review_for_id] => 54f25         [review_for_type] => city         [r_title] => asfasas asd         [r_body] => sdasda sdas dasdas das d         [r_rating] => 3         [other_info] =>          [added] => 2015-03-28 15:47:20         [modified] => 2015-03-28 15:47:20         [f_name] => abc         [l_name] => xyz         [lives_in] => abc     )  ) 

php- above array comes in $d

json_encode($d, json_hex_tag | json_hex_quot) 

here jquery ajax:

 $.get(url, '', function(d){     var data = {};     if(d != ''){         data = $.parsejson(d);     }     var acc = {};     acc[sc_id] = data;     console.log(acc); }); 

please help!

<script>     var str = '[{"id":"2","user_id":"53b595a","review_for_id":"54f25","review_for_type":"city","r_title":"asfasas asd as","r_body":"a sdasda sdas dasdas das d","r_rating":"3","other_info":"","added":"2015-03-28 15:47:20","modified":"2015-03-28 15:47:20","f_name":"abc","l_name":"xyz","lives_in":"abc"}]';     var obj = $.parsejson(str);     alert(obj.id); </script> 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -