The json response return (from ajax function) :
{
"shoe_products":"{name: 'nike pegasus 35',data: [56.00,43.00,32.00], stack: 'Nike'},{name: 'adidas ultraboost',data: [32.00,34.00,35.00,0,55.0], stack: 'Adidas'}"
}
This is string after I debug it using alert(typeof data.myjson). The problem is, I can't convert it to object.
var myobj = JSON.parse(data.shoe_products); //this will return Unexpected token n in JSON at position 1
But if I do the code below, it return as an object.
var test = [{"shoe_products":"{name: 'nike pegasus 35',data: [56.00,43.00,32.00], stack: 'Nike'},{name: 'adidas ultraboost',data: [32.00,34.00,35.00,0,55.0], stack: 'Adidas'}"}];
Ajax function
$.ajax({
type: "POST",
url: urlLinkHere,
data: { "year" : year },
success: function(data) {
var myobj = JSON.parse(data.shoe_products);
}
});
});
{"name":...}instead of{name:...}