So I have this JSON object:
[
{
"branch_id": "1",
"issue_id": "1",
"user_id": "5",
"parent_id": null,
"level": "1",
"name": "troll",
"description": "yup",
"add_date": "2012-10-24 20:26:04",
"children": [
{
"branch_id": "2",
"issue_id": "1",
"user_id": "5",
"parent_id": "1",
"level": "2",
"name": "sdad",
"description": "dssfsd",
"add_date": "2012-10-24 20:52:52",
"children": [
{
"branch_id": "4",
"issue_id": "1",
"user_id": "5",
"parent_id": "2",
"level": "3",
"name": "fdgffd",
"description": "ghjjhjghjj",
"add_date": "2012-10-25 17:51:53",
"children": []
}
]
}
]
},
{
"branch_id": "3",
"issue_id": "1",
"user_id": "5",
"parent_id": null,
"level": "1",
"name": "dgdfg",
"description": "dfgfgdfg",
"add_date": "2012-10-24 20:52:52",
"children": []
}
]
For some reason, when I try to decode it with PHP's json_decode, it doesn't output anything. The object can't be invalid, because both JSONLint and this parser parse it correctly and throw no errors. PHP's own json_last_error method doesn't throw any errors either.
I think the non-existent output might have something to do with the object having multidimensional arrays, but I'm not sure. What do you think?
EDIT
A little background here:
This JSON object is retrieved from this file. It's from an (in development) API, and this particular resource returns a JSON object from a certain "branch collection". I fetch this JSON object to PHP with cUrl, here's the code for that:
$ch = curl_init('http://skibb.it/api/issues/branches?issue_id=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$branches = curl_exec($ch);
curl_close($ch);
That should be also error free, because it gets the plain JSON object correctly. But when I try:
$branches = json_decode($branches);
var_dump($branches); //Or print_r($branches);
It just doesn't output anything, except NULL.
FINAL EDIT
Yup, this is embarassing. Found out after looking through the code, that I had accidentaly left a print_r() in the encoding process during debugging phase, which outputted the JSON object and a number 1 after it. But thanks for the replies, they were helpfull in distinguishing the problem's source!