我有来自API的json结果:
{
"pagination":
{
"results" : 2248,
"page" : 1,
"page_size" : 200,
**"pages" : 12**
},
"products" :
[ {"id": "370c3876-a2b9-11e2-b2b4-bc764e10976c", "source_id": "",....}]}
我想从分页中检索“pages”:12 。我该怎么办?
答案 0 :(得分:2)
我试过这个并且工作正常
$data = ' {
"pagination":
{
"results" : 2248,
"page" : 1,
"page_size" : 200,
"pages" : 12
}
}';
$response = json_decode($data, true);
echo $response['pagination']['pages'];//12
答案 1 :(得分:1)
使用json_decode
解码api响应,然后访问该属性。
示例:
$response = json_decode($data, true);
echo $response['pagination']['pages'];
答案 2 :(得分:0)
<?php
$object = json_decode($your_api_return_string);
$pages = $object->pagination->pages;
echo $pages;
?>