$str='{"data":[{"name":"111","img":"748.jpg","dz":"uang","sz":"22"},{"name":"222","img":"888.jpg","dz":"ngzhu","sz":"13"},{"name":"333","img":"999.jpg","dz":"ve","sz":"27"}]}';
目前創(chuàng)新互聯(lián)已為近千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁(yè)空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、清遠(yuǎn)網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
$json=json_decode($str,true);
echo?$json['data'][0]['name']."br?/";
echo?$json['data'][0]['img']."br?/";
echo?$json['data'][0]['dz']."br?/";
echo?$json['data'][0]['sz']."br?/";
//或者
$json=json_decode($str);
echo?$json-data[0]-name."br?/";
echo?$json-data[0]-img."br?/";
echo?$json-data[0]-dz."br?/";
echo?$json-data[0]-sz."br?/";
遍歷數(shù)據(jù)表,把相應(yīng)的數(shù)據(jù)放到數(shù)組中即可
例如:
?php
//定義一個(gè)數(shù)組,用于保存讀取到的數(shù)據(jù)
$contents = array();
$query = mysql_query("select * from table");
//遍歷數(shù)據(jù)表
while($array = mysql_fetch_array($query)){
$contents[] = $array;
}
print_r($contents);
//然后循環(huán)數(shù)組,或者通過(guò)鍵名使用數(shù)組
foreach($contents as $value){
print_r($value);
}
echo $contents[0]['字段名稱'];
?
數(shù)據(jù)庫(kù)提到的數(shù)據(jù)一般是資源類型的,要逐一讀出,添加到數(shù)組
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}