Home > Backend Development > PHP Tutorial > 获取message中的值

获取message中的值

WBOY
Release: 2016-06-06 20:48:26
Original
1493 people have browsed it

<code>http://git.oschina.net/startbbs/startbbs/graph/master.json
</code>
Copy after login
Copy after login

这里是一段json数据,想获取message的值,循环出来。如何弄。 先转成数组,对吧

回复内容:

<code>http://git.oschina.net/startbbs/startbbs/graph/master.json
</code>
Copy after login
Copy after login

这里是一段json数据,想获取message的值,循环出来。如何弄。 先转成数组,对吧

<code><?php $message = array();
    $json = json_decode(
         file_get_contents('http://git.oschina.net/startbbs/startbbs/graph/master.json'),
         true);
    foreach($json['commits'] as $commit) 
         $message[] = $commit['message'];
    print_r($message);
?>
</code>
Copy after login
Copy after login

<code><?php $message = array();
    $json = json_decode(
         file_get_contents('http://git.oschina.net/startbbs/startbbs/graph/master.json'),
         true);
    foreach($json['commits'] as $commit) 
         $message[] = $commit['message'];
    print_r($message);
?>
</code>
Copy after login
Copy after login

用curl取得url里的json值,再json_decode得到数组$arr,循环$arr['commits']得到message的值

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template