Closed nlamirault closed 7 years ago
According to PHP documentation, there is 2 possible outputs :
echo "Empty array output as array: ", json_encode($b), "\n";
RESULT: Empty array output as array: []
echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\n\n";
RESULT: Empty array output as object: {}
Change function in https://github.com/pi-hole/AdminLTE/blob/master/api.php#L63 in 👍
echo json_encode($data, JSON_FORCE_OBJECT);
could solve problem ...
Just tested it. Your proposed change causes problems in the current version of the devel
branch. The main diagram (Queries over Time) does not load anymore because of invalid data format. I'm currently looking into this and will open a PR as soon as I find a solution.
Although I've been able to solve the issue with the main diagram, it causes additional trouble with "Recent Queries" which might not be able to be solved straightforwardly. You can have a look at what I did to make it working on the main page here.
@nlamirault The change you suggested cause unpleasant trouble with DataTables. Also, I don't want to break anything else users might have invented that relies on our API how it is.
However, what do you think about having an option to get the behavior you want/need?
Example:
api.php?xyz
[]
api.php?xyz&jsonForceObject
{}
api.php?getAllQueries
{"data":[["2016-11-24T00:00:04","A","xyz.de","x.y.z.w","OK",""],
api.php?getAllQueries&jsonForceObject
{"data":{"0":{"0":"2016-11-24T00:00:04","1":"A","2":"xyz.de","3":"x.y.z.w","4":"OK","5":""},
@DL6ER Perfect.
Update has been released
Expected Behaviour:
When i've got Top Ads, result looks like a map, while when TopAds are empty results seems to be an array.
See: https://github.com/nlamirault/pihole_exporter/issues/1
Actual Behaviour:
Without TopAds it seems to be an array. With TopAds, it seems to be a map :
Steps to reproduce this issue:
Launch a fresh installation of PiHole.