程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php解析json數據,php解析json

php解析json數據,php解析json

編輯:關於PHP編程

php解析json數據,php解析json


<?php

$data;
$data.="[";
for ($i=0;$i<20;$i++)
{
$data.="{";

$data.="\"id\":\"" . 110 . "\",";
$data.="\"name\":\"" . 110 . "\",";
$data.="\"original_price\":\""
. 110 . "\",";
$data.="\"sale_price\":\""
. 110 . "\",";
$data.="\"introduce\":\"" . 110
. "\",";
$data.="\"content\":\"" . 110
. "\",";
$data.="\"nums\":" . 110 . "";

$data.="}";
if($i<19)
{
$data.=",";
}
}
$data.="]";

 

 

//解析 前提是$data是json格式

$array=array();

$de_json=json_decode($data,true);
//var_dump($de_json);
$count_json = count($de_json);
for ($i = 0; $i < $count_json; $i++)
{
$array[$i]["id"] = $de_json[$i]['id'];
$array[$i]["name"] = $de_json[$i]['name'];
$array[$i]["original_price"] = $de_json[$i]['original_price'];
$array[$i]["sale_price"] = json_encode($de_json[$i]['sale_price']);

}
var_dump($array);

 

 

?>


php解析json數據的問題,尋找高人指點

PHP有提供對JSON的解析支持,可以使用函數:json_decode

$json_string = <<<EOT
{
"status":"Success",
"request":{
"method":"POST",
"parameters":[
{
"name":"email",
"value":"[email protected]"
},
{
"name":"apikey",
"value":"ABCDEFG123456"
}
],
"from":"192.168.30.40",
"timestamp":1343285417993
},
"duration":14,
"logon_user":{
"guid":108142,
"email":"[email protected]",
"device_number":"UNKNOWN",
"is_male":true,
"role":"USER",
"account_state":"ACTIVE",
"logon_times":19,
"last_logon_time":1343285418001,
"last_logon_by":"EMAIL",
"logon_host":"192.168.30.40",
"logon_token":"43O8NNVC3U8KBI5OT1N07PNZF0C28AGI",
"created_time":1343193738000,
"mobile_phone":"UNKNOWN",
"display_name":"lee.li",
"is_verified":false
}
}
EOT;

$json_object = json_decode($json_string);
echo $json_object->logon_user->guid;
參考資料:cn.php.net/...de.php...余下全文>>
 

PHP解析Json數據的問題們幫幫忙

原始數據就是代碼,你需要進行哈希轉碼啊 至於時間的話轉換的話,相關發給你的QQ郵箱 才10分好摳門啊
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved