我試圖從API解析json響應,但購買改變了我創建的一些現有的PHP代碼,但是我有困難。這是JSON響應解析來自API的json響應與PHP
"response":{
"status":"ok",
"userTier":"free",
"total":10,
"startIndex":1,
"pageSize":10,
"currentPage":1,
"pages":1,
"results":[{
"id":"lifeandstyle/series/cycling",
"type":"series",
"webTitle":"Cycling",
"webUrl":"http://www.guardian.co.uk/lifeandstyle/series/cycling",
"apiUrl":"http://content.guardianapis.com/lifeandstyle/series/cycling",
"sectionId":"lifeandstyle",
"sectionName":"Life and style"
}
試圖將「webTitle」和「WEBURL」部分
<?php
require_once 'Zend/Json.php';
$val = Zend_Json::decode($result);
$arr = $val;
if(preg_match_all("~<p>([\s\S]*?)</p>~i", $arr['parse']['text']['*'], $matches)){
if(is_array($matches[1])) foreach($matches[1] as $paragraph){
echo $paragraph;
}
}
?>
此代碼只是在解析p標籤內容中解析所有的信息,我會如何改變呢?
謝謝