I'm generating a json file with php and store it on my server. Here is the code for exporting the json
/**
* FUNCTIONS TO EXPORT AS JSON
*/
public function expose() {
return array(
'guid' => $this->guid,
'title' => $this->title,
'folder' => $this->folder,
'owner' => $this->owner,
#'pictures' => json_encode(array_values($this->pictures), JSON_FORCE_OBJECT),
'excude' => $this->excude,
'added' => $this->added,
'lastViewed' => $this->lastViewed,
);
#return get_object_vars($this);
}
public function toJSON(){
return json_encode($this->expose(), JSON_FORCE_OBJECT);
}
The content of the file is this:
{"guid":"","title":"Sample Gallery","folder":"sampleGallery","owner":"","excude":true,"added":"","lastViewed":""}
then in my html file I try to load this with jquery, but I fail to get the objects to the console
$.getJSON('/files/galleries/index/sampleGallery.gallery', function(data) {
console.log(data); // works!
var jsonObj = jQuery.parseJSON(data);
for (key in jsonObj) {
console.log(key+':'+JSON.stringify(jsonObj[key]));
}
});
Note that the loading of json works fine!
Can someone tell me what I am doing wrong? Thanks in advance!