Question

Hello i am new with Json in php. I have a web service that gives me data in json format. I take this data making decode put when i try to use this data i cant

Here is my code:

 $url = "http://www.webinsurer.gr/....;

    $json = json_decode(@file_get_contents($url), true);

and if i make debug i see the data i take :

[file] => C:\xampp\htdocs\development.insurancemarket.gr\mvc\protected\models\Ratingsmail.php
[line] => 18
[data] => Array
    (
        [0] => Array
            (
                [POL_EXPIREDATE] => 2014-05-19 12:00:00
                [INCO_IWCODE] => 41
                [INCO_DESC] => MAPFRE ASISTENCIA
                [PACK_IWCODE] => 0
                [PACK_DESC] => 
                [OFFERCODE] => 
                [PAYMENTCODE] => 
            )

        [1] => Array
            (.....

But i dont now how to use that data. when i try this :

$b= $json->{1}->{'INCO_IWCODE'};

    Debug::debuger($b);

the result is nothing

what is wrong? sorry for long post.

Était-ce utile?

La solution

When setting the second argument on json_decode to true, you are actively asking for the data to be returned in an associative array and not objects. Thats why your code didn't work.

Autres conseils

Demo

You are converting json to associative array. You need to use;

$b = $json["data"][1]["INCO_IWCODE"];

$a = $json[0]->INCO_IWCODE;

That worked for my guys. thanks you all!!!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top