Posted by atrasatti 3 years 40 weeks ago
Following up from comment on PHP article.
javierliu wrote:
I downloaded sample.json from "http://deviceatlas.com/node/305997/"
I use the "json_decode" , but only got null value . that's strange .
following is my test code . Could anyone help me ? thx a lot .$json1 = file_get_contents("json/Sample.json"); $json2 ='{"a":1,"b":2,"c":3,"d":4,"e":5}'; $tree1 = json_decode($json1); $tree2 = json_decode($json2); var_dump($tree1); var_dump($tree2);This is my result:
null object(stdClass)[1] public 'a' => int 1 public 'b' => int 2 public 'c' => int 3 public 'd' => int 4 public 'e' => int 5
Javier,
why do you need to decode the JSON? The API should do all the hard work for you.
Did you read the API documentation? What PHP version are you running?




Posted by javierliu 3 years ago
Hi atrasatti ,
When I try the example in DA_php_1.3.1/sample/index.php , I got the error message :
Mobi_Mtld_Da_Exception_JsonException: Unable to load Json data. in /home/staff/cwliu/project/FINDBOOK_MOBILE/root/DA_php_1.3.1/Mobi/Mtld/DA/Api.php on line 88
So ,I trace the code in Api.php . find the $tree is null @@
My environment is :PHP Version 5.2.3
thanks for your help .
Posted by daniel.hunt 3 years ago
Mobile Grandmaster
Well, that's an interesting problem. I had the exact same issue yesterday while developing!
Check the file permissions on the JSON file. For some reason the extracted file had permissions of 600, so the webserver didn't have permission to read it (it was owned by me).
All I did was a simple
Daniel Huntchmod 644 DeviceAtlas.jsonand all was fine and dandy again.dotMobi
Posted by javierliu 3 years ago
Hello ~
Following is my test code :
$json1 = file_get_contents("Sample.json"); $json2 = file_get_contents("t2.json"); var_dump($json1); var_dump($json2); $tree1 = json_decode($json1); $tree2 = json_decode($json2); var_dump($tree1); var_dump($tree2);And my result is :
string '{"$":{"Ver":"0.7","Rev":"$Rev: 2914 $","Gen":"01 Apr 2008","Utc":1207083104},"v":[1,120,100,8,"NEC","c313",207687,"c616",207693,131072,128,12,"Alcatel","One Touch 535",0,205100,"Samsung","SPH-A660",203262,16384,32000,176,220,16,"Audiovox","SMT-5600",205308,240,160,"BlackBerry 7230","RIM",209211,32768,320,"BlackBerry 8700v",209265,"BlackBerry 8707v",209274,20480,132,162,"e606",207725,"LG","G8000",206177,102400,"C1100",205917,4096,"C2000",205941,261120,"G5300i",206127,"G5400",206133,26100,"G7030",206156,"G710'... (length=520463) string '{"a":1,"b":2,"c":3,"d":4,"e":5} ' (length=32) null object(stdClass)[1] public 'a' => int 1 public 'b' => int 2 public 'c' => int 3 public 'd' => int 4 public 'e' => int 5I think the web server has the permissions to read the file . because var_dump($json1) has value .
@@ Is it has any possibility that the Sample.jon is browken ? @@
Thanks for your help .
Cwliu
Posted by adrian.hopebailie 3 years ago
Hi javierliu,
Unfortunately PHP doesn't give us much help when it is unable to decode the JSON we supply to json_decode().
It looks like json_decode is returning a blank when you try to decode our JSON.
This usually occurs when you are running an older version of PHP and the JSON data is quite large/complicated.
I have never seen it happen with PHP v 5.2.3 or higher.
Are you able to test this on a newer version of PHP to eliminate that possible solution?
Adrian Hope-Bailie
Adrian Hope-BailiedotMobi
Posted by atrasatti 3 years ago
Mobile Genius
If you look on the PHP site you'll see that they mention the JSON library must be at least 1.2.0 in order to work up to a depth of 127 elements. See json_decode. You might to look into your phpinfo() and see the json version.
On my development server, for example, I have PHP 5.2.5 and see "json version 1.2.1" in the phpinfo.
Posted by javierliu 3 years ago
Hi adrian.hopebailie & atrasatti ,
In phpinfo :
json
json support enabled
json version 1.2.1
Well , I just want to try DeviceAtlas in order to see how it works . In my application , That is not a important feature , so I would try the newer php version later .
However , It's still a big hand for me. ^^
Javie Liu
Posted by atrasatti 3 years ago
Mobile Genius
Javier,
did you try getting a developer licence and downloading the latest JSON? Could you please let me know if that works for you?
The sample file is included in the package to let our users have a quick start, if it doesn't work, we have a problem. :)
Posted by JWiden 3 years ago
I'm having the exact same problem so it would be nice to know if you came up with a solution. Did you get it to work?
Having the problem running on PHP v5.2.3 and json v1.2.1.
It works fine on my local machine running PHP v5.2.6 and json v1.2.1
-Joachim
Posted by adrian.hopebailie 3 years ago
Hi Joachim,
Unfortunately this is a known issue with PHP's json_decode function. Unfortunately there is very little documentation around on the subject but we have nailed it down to the fact that older versions of PHP are unable to decode a JSON object that recurses too deep.
In this case json_decode will simply return NULL. We have tested machines running PHP 5.2.3 and had no problems which is why we made it our required version.
It could be that your 5.2.3 machine has somehow been compiled with some old PHP sources that still have a recursion limit too low to decode our JSON?
Basically an upgrade to your PHP version should solve the issue.
Adrian Hope-Bailie
Adrian Hope-BailiedotMobi
dotMobi
Posted by JWiden 3 years ago
Thanks for you reply Adrian. Unfortunately I'm not in control over the server I'm trying to use and I'm suspecting it won't be upgraded in the near future. Guess I'll have to find an alternative server to use then.
Thanks again,
Joachim
Posted by JWiden 3 years ago
I have now got my hosting company to update to PHP v5.2.6 and I still get the same error.
Fatal error: Uncaught exception 'Mobi_Mtld_Da_Exception_JsonException' with message 'Unable to load Json data.' in /Mobi/Mtld/DA/Api.php:89
Stack trace:
#0 Mobi/Mtld/DA/Api.php(133): Mobi_Mtld_DA_Api::getTreeFromString('{"$":{"Ver":"2....') #1 init.php(17): Mobi_Mtld_DA_Api::getTreeFromFile('json/deviceAtla...')
#2 index.php(4): require_once('/www/webvol7/wl...')
#3 {main} thrown in Mobi/Mtld/DA/Api.php on line 89
Any other ideas on what I'm doing wrong?
Regards,
Joachim
Posted by adrian.hopebailie 3 years ago
Hi Joachim,
Can I ask that you zip up the PHP files you are using and email them to me.
ahopebailie at mtld dot mobi
I'll see if I can spot what the problem may be. Did you say you are able to run the same code on your local dev machine?
Adrian Hope-BailiedotMobi
Posted by preason 2 years ago
Hi, I'm following the Device Atlas API tutorial in php.
Have done steps 1 & 2 ok.
In step 3 have changed a path to json/sample.json but viewing the page in a browser shows nothing on the screen at all.
I've got index.php & all files in folder test_area/
Mobi file is there & json file also Mobi_Mtld_DA & Mobi_Mtld_DA_exception
Can anybody help please?
Just in case you need it, I've attached index.php
Thanks from Peter
Posted by preason 2 years ago
I guess it's the php version 5.2.3 requirement that's a problem.
My hosting company used to be good at keeping up with the latest ones and posting the current versions but now it's been removed, so I'm waiting for their reply.........zzzzzzz,
from Peter
Posted by sohnyrin 2 years ago
I've got a similar problem. My scripts intrgrating DA work perfectly on my local dev machine but on the hosting machine i get this error :
They are running PHP 5.2.8 and json 1.2.1
Any idea ?
Posted by ouendinga 2 years ago
Hello,
I have the same problem, I tried it different from other json DeviceAtlas and working properly. Why could this happen?
PHP: 5.2.12
JSON: enabled, 1.2.1
IFatal error: Uncaught exception 'Mobi_Mtld_Da_Exception_JsonException' with message 'Unable to load Json data.' in /DeviceAtlas/Mobi/Mtld/DA/Api.php:87 Stack trace: #0 /DeviceAtlas/Mobi/Mtld/DA/Api.php(129): Mobi_Mtld_DA_Api::getTreeFromString('{"$":{"Ver":"0....') #1 /DeviceAtlas/sample/index.php(17): Mobi_Mtld_DA_Api::getTreeFromFile('json/Sample.jso...') #2 {main} thrown in /DeviceAtlas/Mobi/Mtld/DA/Api.php on line 87Posted by daniel.hunt 2 years ago
Mobile Grandmaster
Have you checked to see if it's a permissions issue? Does your webserver have access to read the file?
Daniel HuntdotMobi
Posted by ouendinga 2 years ago
The web folder and the folder of apache have permissions 777.
For if it helps
Structure:
DeviceAtlas
---json
------DeviceAtlas.json
---Mobi
------Mtld
---------DA
------------Exception
---------------...
------------Api.php
------------JSON.php
------------Test.php
---sample
------json
---------Sample.json
---------test.json
------index.php
------prueba.php
---index.php
Missing test files that are not critical mine
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
What about your apache logs? Does anything look out of the ordinary? Any errors popping up?
Daniel HuntAnd your php logs too...
dotMobi
Posted by garbetjie 2 years ago
One thing that I have encountered, is that my PHP version is given as 5.2.10-2ubuntu6.4. This seems to break the version_compare() function used.
I've had to hack the source to get it working, so that I explode() out by the dash (if it is found), and then use the new value to compare PHP versions.
Strangely enough though, I now have issues with the JSON parsing too, whereas I never had them before.
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
This is becoming annoying :)
Can you send me the JSON file you're using please? (both OUENDINGA and GARBETJIE) dhunt A.T mtld D.O.T mobi
I think I should probably give the files a once-over just to make sure that this isn't something small like a bad data file ...
@Geoff: When did the JSON parsing first start causing issues for you? Have you noticed anything strange in your Apache and/or your PHP logs?
Daniel HuntdotMobi
Posted by ouendinga 2 years ago
Errors Apache: Nothing
Errors PHP:
[24-Feb-2010 09:25:22] PHP Fatal error: Uncaught exception 'Mobi_Mtld_Da_Exception_JsonException' with message 'Unable to load Json data.' in /usr/home/mcario/www/m.cdmon.com/web/prod/alvaro/DeviceAtlas/Mobi/Mtld/DA/Api.php:87
Stack trace:
#0 /usr/home/mcario/www/m.cdmon.com/web/prod/alvaro/DeviceAtlas/Mobi/Mtld/DA/Api.php(129): Mobi_Mtld_DA_Api::getTreeFromString('{"$":{"Ver":"0....')
#1 /usr/home/mcario/www/m.cdmon.com/web/prod/alvaro/DeviceAtlas/index.php(3): Mobi_Mtld_DA_Api::getTreeFromFile('Sample.json')
#2 {main}
thrown in /usr/home/mcario/www/m.cdmon.com/web/prod/alvaro/DeviceAtlas/Mobi/Mtld/DA/Api.php on line 87
Operating System: FreeBSD 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Wed Jan 21 18:19:54 CET 2009
Apache version: Server version: Apache/2.0.59
PHP version: 5.2.12
JSON version: 1.2.1
Posted by ouendinga 2 years ago
You can download json:
http://jonirubio.com/prod/alvaro/DeviceAtlas/json/DeviceAtlas.json
http://jonirubio.com/prod/alvaro/DeviceAtlas/Sample.json
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
Thanks for that. The file itself is perfectly fine - no issues whatsoever with it recognising UA strings using the PHP, Java or C++ apis (including the Apache module).
Daniel HuntWhen did you last download the PHP API?
dotMobi
Posted by ouendinga 2 years ago
I download it on 19 January 2010 File name DA_php_1.3.1.zip, 131kB
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
That's the same one I'm testing this on.
This is all very strange.
Can you give me some info about your Operating System? Maybe we can narrow this down some other way
Daniel HuntdotMobi
Posted by ouendinga 2 years ago
Hello
I've test the same files with an Operating System Devian, and worked for the former.
I will investigate further informs you on the forum.
Thanks for the help
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
Ah, so it could well be a local setup issue.
Daniel HuntWell, make sure you let us know how you get on - if this crops up again it'd be nice to know where to look!
dotMobi
Posted by ouendinga 2 years ago
Hello
I've tried it in a Devian and a Free BSD 7 and it works
But it has not worked in a Free BSD 6 (the first to prove)
It can be because of the extensions that are installed. But I do not know which one.
Someone knows what could be?
Which extensions has to be installed?
Posted by cornilliat 2 years ago
Hi,
I have a blocking issue using DA Beta 2.3. Can you help ?
The issue is with Mobi_Mtld_DA_Api::getTreeFromFile(json/DeviceAtlas.json) which never completes while raising no exception. The following code displays
'getTreeFromFile to start'
but never
'getTreeFromFile complete'.
It seems code execution is stalled or stuck in endless loop.
Code:
require_once 'library/Mobi/Mtld/DA/Api.php';
echo 'getTreeFromFile to start';
try{
$tree = Mobi_Mtld_DA_Api::getTreeFromFile('json/DeviceAtlas.json');
} catch (Mobi_Mtld_DA_Exception_JsonException $e) {
echo 'error :'.$e;
}
echo 'getTreeFromFile complete';
The server configuration is Linux / Apache 2.2.13 / PHP 5.2.11 / json enabled / json 1.2.1
DeviceAtlas version is : beta 2.3 / DeviceAtlas.json is latest file, dated April 30th, 2010.
DeviceAtlas.json file rights are rwx/r--/r-- (should be OK)
Thanks for your help.
BC
Posted by esuen 2 years ago
I'm having the same issue with
php 5.2.6
json 1.2.1
Ubuntu 9.19
DA_php_1.3.1
Using the jsons that ouendinga provided above,
DeviceAtlas.json does not work but Sample.json does.
Posted by daniel.hunt 2 years ago
Mobile Grandmaster
Hey guys,
The DA 2.x APIs have been removed from the DeviceAtlas site for now. They are beta APIs, so you really shouldn't be using them in a live environment.
I suggest you move back to the 1.x API until we release a new beta!
Daniel
Daniel HuntdotMobi
Posted by xiaopy12 1 week ago
Christian Louboutin Sale ghrtuj