I have a little experience in JSON I did it on my Android application now using JSON again in my webpage as AJAX reponse, I did research about ajax and found a tutorial to get my data in database using JSON so I tried but I didn't know how to parse the object.
My Jquery Code.
$.ajax({
type: 'GET',
dataType: 'json',
url: 'functions/json.php',
success: function(response){
var json = $.parseJSON(response);
alert(json.firstname) //where my response is $response['firstname']
},
error: function(data){
var json = $.parseJSON(data);
alert(json.error);
}
});
Using the php I echo the jsonArray as json_encode and heres the json output
{"id":"2","firstname":"john","lastname":"Doe"}
using google chrome console i got this error
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
when the function response output as alert(reponse) output was
[object Object]