error on json parsing on ajax callback
I am making an ajax call which return the following json
- {"0":"37","id":"37","1":"1","hand_tool_categoy":"1","2":"10 Pcs Allen Key Set","name":"10 Pcs Allen Key Set","3":"handtools182.jpg","image":"handtools182.jpg","4":"ht","type":"ht","5":"{\"f_1\":{\"val\":\"RST- 6A101C\",\"name\":\"art_no\"},\"f_2\":{\"val\":\"\",\"name\":\"feature\"},\"f_3\":{\"val\":\"1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 8 & 10 mm\r\n1\/16, 5\/64, 3\/34, 1\/18, 5\/32, 3\/16, 7\/32, 1\/4, 5\/16, 3\/8 inches\",\"name\":\"size\"},\"f_4\":{\"val\":\"100 set\/ctn\",\"name\":\"packing\"},\"f_5\":{\"val\":\"\",\"name\":\"highlights\"},\"f_6\":{\"val\":\"\",\"name\":\"contents\"},\"f_7\":{\"val\":\"\",\"name\":\"price\"}}","details":"{\"f_1\":{\"val\":\"RST- 6A101C\",\"name\":\"art_no\"},\"f_2\":{\"val\":\"\",\"name\":\"feature\"},\"f_3\":{\"val\":\"1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 8 & 10 mm\r\n1\/16, 5\/64, 3\/34, 1\/18, 5\/32, 3\/16, 7\/32, 1\/4, 5\/16, 3\/8 inches\",\"name\":\"size\"},\"f_4\":{\"val\":\"100 set\/ctn\",\"name\":\"packing\"},\"f_5\":{\"val\":\"\",\"name\":\"highlights\"},\"f_6\":{\"val\":\"\",\"name\":\"contents\"},\"f_7\":{\"val\":\"\",\"name\":\"price\"}}"}
The jquery ajax call is as
- $.ajax({
- type : "POST",
- cache : false,
- url : "admin_managehtitem.php?action=getdetails&id="+id,
- data : '',
- success : function(data) {
- console.log(data);
- var obj = JSON.parse(data);
- console.log(obj);
- var obj2 = JSON.parse(obj.details);
- console.log(obj2);
- },
- error: function() {
- alert("Some internal error occurred. Please try again!");
- }
- });
- I am doing JSON.parse on the data
- var obj = JSON.parse(data);
- var obj2 = JSON.parse(obj.details);
But I am getting this error on the second
JSON.parse for
obj.details
Uncaught SyntaxError: Unexpected token
That is coming up perhaps because of the slash characters.
The json is formed on php side using
- json_encode($db->Record);
Moreover when i add the following on server side
- header("content-type:application/json");
the callback enters the error part!
How can i handle such situation. Thanks