在php中显示JSON数据

在php中显示JSON数据,php,json,Php,Json,从SDK中,我的json数据如下所示: $count_categories_json = "{\"api\": {\"version\":\"1.0\",\"cal_url\":\"http:\/\/www.example.com\",\"encoding\":\"ISO-8859-1\",\"generated\":\"2014-01-20T17:23:21+01:00\",\"contents\":\"categories_event_count\"} ,\"0\":{\"id\":\"47

从SDK中,我的json数据如下所示:

$count_categories_json = "{\"api\":
{\"version\":\"1.0\",\"cal_url\":\"http:\/\/www.example.com\",\"encoding\":\"ISO-8859-1\",\"generated\":\"2014-01-20T17:23:21+01:00\",\"contents\":\"categories_event_count\"}
,\"0\":{\"id\":\"47\",\"name\":\"Expositions\",\"parent_id\":\"0\",\"event_count\":\"679\",\"rank\":1}
,\"1\":{\"id\":\"94\",\"name\":\"Gratuit\",\"parent_id\":\"56\",\"event_count\":\"598\",\"rank\":2}
…}
显示下面的代码

事件-

679项活动-展览

598项活动-小费

$array=json\u decode($count\u categories\u json,true);
foreach($jsons形式的数组){
回显“
  • ”.$jsonsc3['event_count']”事件-“.$jsonsc3['name']”。
  • ; }
    第一个lign当然是不需要的,它来自json的第一个元素(“api”:{“version\”:“1.0\”,\…)

    问题是:如何不去支付它

    $array = json_decode($count_categories_json,true);
    
    array_shift($array);
    
    foreach...
    

    将删除第一个数组元素。

    在您的
    foreach
    之前,添加以下内容:

    unset($array['api']);
    
    这将从JSON对象中删除“api”属性

    或者,在
    foreach
    循环中,添加:

    if ( !isset($jsons['id']) ) continue;
    
    这将跳过未定义“id”属性的每一行

    if ( !isset($jsons['id']) ) continue;