使用php从JSON获取数据 [英] get data from JSON with php

查看:109
本文介绍了使用php从JSON获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从JSON页面获取数据:
http:/ /www.oref.org.il/WarningMessages/alerts.json



我收到错误。



如何从JSON获取data数组?

下面是一个例子,我在做:

  $ homepage = file_get_contents('http://www.oref.org.il/WarningMessages/alerts.json ); 
$ result = json_decode($ result);
$ result = utf8_encode($ result);
print_r($ result);


解决方案

$ result = file_get_contents( http://www.oref.org.il/WarningMessages/alerts.json ); p>

  $ result = iconv('UTF-16','UTF-8',$ result); 
$ json = json_decode($ result);
echo $ json-> id;
echo $ json-> title;


I am trying to get data from a JSON page: http://www.oref.org.il/WarningMessages/alerts.json

I am getting errors.

How do I get the "data" array from the JSON?

Here is an example of what I am doing:

$homepage = file_get_contents('http://www.oref.org.il/WarningMessages/alerts.json');
$result   = json_decode($result);
$result   = utf8_encode($result); 
print_r($result);

解决方案

$result = file_get_contents ("http://www.oref.org.il/WarningMessages/alerts.json");

 $result = iconv('UTF-16', 'UTF-8', $result);
 $json = json_decode($result);
 echo $json->id;
 echo $json->title;

这篇关于使用php从JSON获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆