doucanshou6998 2017-04-23 18:53
浏览 54
已采纳

php Wikipedia API JSON获取页面ID

I want to get some wikipedia information using their api but how would I get the page id? Because it is in the JSON array.

echo $json["query"]["pages"][HERE_IS_THE_PAGE_ID]["pageid"];
  • 写回答

1条回答 默认 最新

  • douke9545 2017-04-24 17:57
    关注

    One way is to loop through the "pages" array.

    foreach ($json["query"]["pages"] as $page_id => $this_page) {
        echo $page_id;
        // OR
        echo $this_page['pageid'];
    }
    

    If you're certain that the data only contains one page, you could just access the array key:

    $page_id = key($json["query"]["pages"]);
    

    Here's an example.

    Or use current() or reset() to access the (first) page array:

    $this_page = current($data["Something is wrong"]["pages"]);
    $page_id=$this_page["pageid"];
    

    Here's an example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器