Rumah > pembangunan bahagian belakang > tutorial php > php怎么循环读取该数据?

php怎么循环读取该数据?

WBOY
Lepaskan: 2016-06-23 14:38:20
asal
857 orang telah melayarinya

Body:[
    {"bucket_name":"wulinag09","status":"0","cdatetime":"1385619473","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag08","status":"0","cdatetime":"1385619360","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag07","status":"0","cdatetime":"1385619169","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag06","status":"0","cdatetime":"1385618406","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag05","status":"0","cdatetime":"1385618247","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag04","status":"0","cdatetime":"1385618074","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag03","status":"0","cdatetime":"1385435678","used_capacity":"0","total_capacity":"0","region":"beijing"},
    {"bucket_name":"wulinag02","status":"0","cdatetime":"1385435395","used_capacity":"0","total_capacity":"0","region":"beijing"}
]


这数据我不知道是什么形式,如何列出每行的数据 这里有8行数据,我想用前端 表格的形式输出8行,然后用变量 读取每行的数据 如:
$rs[bucket_name] 能得到 wulinag09  
$rs[status]      能得到  0
$rs[cdatetime]   能得到  1385619473

依次例推


回复讨论(解决方案)

json数据格式,意思是body的值是整个后面的内容,完整代码如下

<?$body = '[	{"bucket_name":"wulinag09","status":"0","cdatetime":"1385619473","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag08","status":"0","cdatetime":"1385619360","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag07","status":"0","cdatetime":"1385619169","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag06","status":"0","cdatetime":"1385618406","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag05","status":"0","cdatetime":"1385618247","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag04","status":"0","cdatetime":"1385618074","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag03","status":"0","cdatetime":"1385435678","used_capacity":"0","total_capacity":"0","region":"beijing"},	{"bucket_name":"wulinag02","status":"0","cdatetime":"1385435395","used_capacity":"0","total_capacity":"0","region":"beijing"}]';$arrbody = json_decode($body);?><table border=1><tr>	<td>bucket_name</td>	<td>status</td>	<td>cdatetime</td>	<td>used_capacity</td>	<td>total_capacity</td>	<td>region</td></tr><?foreach($arrbody as $key=>$value){?><tr><?	foreach($value as $k=>$var){		echo "<td>$var</td>";	}?></tr><?}?></table>
Salin selepas log masuk

结果:

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan