首页 > 解决方案 > 从 json 打印 PHP 文本

问题描述

Wikipedia API 中有这样一个 json:https ://ru.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Apple

如何从短文本开始的php中的php字段输出文本?

我试过这样,但没有任何效果:

$url = file_get_contents('https://ru.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Apple'); 
$yummy = json_decode($url, true); 
echo $yummy['extract'];

标签: php

解决方案


这样做我调试你在查询>页面>数字中提取的

$url = file_get_contents('https://ru.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Apple'); 
$yummy = json_decode($url, true); 
$datas=$yummy['query']['pages'];

foreach($datas as $data){
  $extract =  $data['extract'];
}

echo $extract;

推荐阅读