>백엔드 개발 >PHP 튜토리얼 >PHP는 json 배열을 구문 분석합니다.

PHP는 json 배열을 구문 분석합니다.

WBOY
WBOY원래의
2016-07-25 09:01:141492검색

  1. $json='[{"name":"qqdeliver","count":198,"average":119.8889},{"name":"load","count":259612,"average":141.9379},{"name":"gate","count":22480,"average":9.2209},{"name":"interact","count":40165,"average":429.3583},{"name":"save","count":2097845,"average":180.6606},{"name":"login","count":29239,"average":322.0906},{"name":"neighbour","count":24777,"average":368.9143},{"name":"updatesave","count":842358,"average":75.1193},{"name":"promotion","count":69417,"average":37.7616},{"name":"activity","count":22978,"average":5.4393},{"name":"message","count":49590,"average":172.3676},{"name":"admin","count":155,"average":750.3032},{"name":"qqpay","count":3078,"average":79.4916},{"name":"alliance","count":54091,"average":120.0409},{"name":"updates","count":189196,"average":54.6144},{"name":"friend","count":26259,"average":101.0704},{"name":"attack","count":8146,"average":205.2529}]';
  2. $obj=json_decode($json);
  3. //print_r($obj);
  4. foreach ( $obj as $unit ){
  5. echo $unit->name.'
    ';
  6. }
  7. ?>
复制代码
  1. $json='[{"name":"qqdeliver","count":198,"average":119.8889},{"name":"load","count":259612,"average":141.9379},{"name":"gate","count":22480,"average":9.2209},{"name":"interact","count":40165,"average":429.3583},{"name":"save","count":2097845,"average":180.6606},{"name":"login","count":29239,"average":322.0906},{"name":"neighbour","count":24777,"average":368.9143},{"name":"updatesave","count":842358,"average":75.1193},{name":"attack","count":8146,"average":205.2529}]';
  2. $obj=json_decode($json);
  3. //print_r($obj);
  4. foreach ( $obj as $unit ){
  5. echo $unit->name.'
    ';
  6. }
  7. ?>
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.