dotMobimobiThinkingmobiForgemobiReadyDeviceAtlasgoMobi

Posted by atrasatti 3 years 40 weeks ago

pic
 atrasatti
dotMobi logo
Mobile Genius
Posts: 325
Joined: 5 years ago
[offline]

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

pic
 javierliu
mobiForge Newbie
Posts: 5
Joined: 3 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

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 chmod 644 DeviceAtlas.json and all was fine and dandy again.

Daniel Hunt
dotMobi

Posted by javierliu 3 years ago

pic
 javierliu
mobiForge Newbie
Posts: 5
Joined: 3 years ago
[offline]

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 5

I 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

pic
 adrian.hopebailie
Mobile Expert
Posts: 51
Joined: 4 years ago
[offline]

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-Bailie
dotMobi

Posted by atrasatti 3 years ago

pic
 atrasatti
dotMobi logo
Mobile Genius
Posts: 325
Joined: 5 years ago
[offline]

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

pic
 javierliu
mobiForge Newbie
Posts: 5
Joined: 3 years ago
[offline]

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

pic
 atrasatti
dotMobi logo
Mobile Genius
Posts: 325
Joined: 5 years ago
[offline]

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

pic
 JWiden
mobiForge Newbie
Posts: 3
Joined: 3 years ago
[offline]

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

pic
 adrian.hopebailie
Mobile Expert
Posts: 51
Joined: 4 years ago
[offline]

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
dotMobi

Adrian Hope-Bailie
dotMobi

Posted by JWiden 3 years ago

pic
 JWiden
mobiForge Newbie
Posts: 3
Joined: 3 years ago
[offline]

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

pic
 JWiden
mobiForge Newbie
Posts: 3
Joined: 3 years ago
[offline]

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

pic
 adrian.hopebailie
Mobile Expert
Posts: 51
Joined: 4 years ago
[offline]

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-Bailie
dotMobi

Posted by preason 2 years ago

pic
 preason
mobiForge Newbie
Posts: 1
Joined: 2 years ago
[offline]

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

AttachmentSize
index.php_.txt1.73 KB

Posted by preason 2 years ago

pic
 preason
mobiForge Newbie
Posts: 1
Joined: 2 years ago
[offline]

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

pic
 sohnyrin
mobiForge Newbie
Posts: 1
Joined: 2 years ago
[offline]

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 :

Quote:
Fatal error: Uncaught exception 'Mobi_Mtld_Da_Exception_JsonException' with message 'Unable to load Json data.' in /home/www/87f0b0edcf6f4c75feccc4e9ef9f48b6/web/test/Mobi/Mtld/DA/Api.php:87 Stack trace: #0 /home/www/87f0b0edcf6f4c75feccc4e9ef9f48b6/web/test/Mobi/Mtld/DA/Api.php(129): Mobi_Mtld_DA_Api::getTreeFromString('{"$":{"Ver":"2....') #1 /home/www/87f0b0edcf6f4c75feccc4e9ef9f48b6/web/test/index.php(4): Mobi_Mtld_DA_Api::getTreeFromFile('json/DeviceAtla...') #2 {main} thrown in /home/www/87f0b0edcf6f4c75feccc4e9ef9f48b6/web/test/Mobi/Mtld/DA/Api.php on line 87

They are running PHP 5.2.8 and json 1.2.1

Any idea ?

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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 87

Posted by daniel.hunt 2 years ago

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

Have you checked to see if it's a permissions issue? Does your webserver have access to read the file?

Daniel Hunt
dotMobi

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

What about your apache logs? Does anything look out of the ordinary? Any errors popping up?
And your php logs too...

Daniel Hunt
dotMobi

Posted by garbetjie 2 years ago

pic
 garbetjie
Mobile Guru
Posts: 70
Joined: 3 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

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 Hunt
dotMobi

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

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).
When did you last download the PHP API?

Daniel Hunt
dotMobi

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

I download it on 19 January 2010 File name DA_php_1.3.1.zip, 131kB

Posted by daniel.hunt 2 years ago

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

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 Hunt
dotMobi

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

Ah, so it could well be a local setup issue.
Well, make sure you let us know how you get on - if this crops up again it'd be nice to know where to look!

Daniel Hunt
dotMobi

Posted by ouendinga 2 years ago

pic
 ouendinga
mobiForge Newbie
Posts: 7
Joined: 2 years ago
[offline]

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

pic
 cornilliat
mobiForge Newbie
Posts: 4
Joined: 2 years ago
[offline]

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

pic
 esuen
mobiForge Newbie
Posts: 2
Joined: 2 years ago
[offline]

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

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

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 Hunt
dotMobi

Posted by xiaopy12 1 week ago

pic
 xiaopy12
Mobile Champion
Posts: 582
Joined: 1 week ago
[offline]

Christian Louboutin Sale ghrtuj