[英]JSON decode in PHP from a url
Hello i am new with Json in php. 您好,我是Json在php中的新手。 I have a web service that gives me data in json format. 我有一个Web服务,可以json格式提供数据。 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. 抱歉,很长一段时间。
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. 将json_decode的第二个参数设置为true时,您正在积极地要求以关联数组而不是对象的形式返回数据。 Thats why your code didn't work. 这就是为什么您的代码无法正常工作的原因。
$a = $json[0]->INCO_IWCODE; $ a = $ json [0]-> INCO_IWCODE;
That worked for my guys. 那为我的家伙工作。 thanks you all!!! 谢谢大家!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.