A. php解析不了JSON
$keys = '{result:0,events:[{event:6}]}'; $string = json_decode($key...
答:json_decode( ) 可以實現對JSON格式的字元串進行編碼 你的Json字元串有問題 結果:array(2) { ["result"] => int(0) ["events"] => array(1) { [0] => array(1) { ["event"] => int(6) } }}
B. PHP 如何解析JOSN格式字元串 轉換為數組
$str = " {"personMsg":{"phone":"11","birth":"2010-07-14","headImg":"11","email":"11","personId":1,"gender":0,"personName":"闄堥"},"friendIdList":["2","10"],"sessionKey":"Oh0aXV/fotUtdV1gTMqI5w==","code":"200","operateData":[{"operate":"1","friendId":"2","version":"3"},{"operate":"2","friendId":"39","version":"4"},{"operate":"1","friendId":"1","version":"21212"},{"operate":"2","friendId":"100","version":"6"},{"operate":"2","friendId":"38","version":"7"},{"operate":"2","friendId":"40","version":"8"},{"operate":"2","friendId":"56","version":"9"},{"operate":"2","friendId":"96","version":"10"},{"operate":"2","friendId":"93","version":"11"},{"operate":"1","friendId":"100","version":"21213"},{"operate":"1","friendId":"39","version":"21214"},{"operate":"1","friendId":"93","version":"21215"},{"operate":"1","friendId":"96","version":"21216"},{"operate":"1","friendId":"10","version":"21217"},{"operate":"1","friendId":"38","version":"21218"},{"operate":"1","friendId":"40","version":"21219"},{"operate":"1","friendId":"40","version":"21220"},{"operate":"1","friendId":"40","version":"21221"},{"operate":"1","friendId":"56","version":"21222"}]}";
var_Export(json_decode($str, 1)); // json_decode 必須指定第二個參數,不然會返回一個對象,而不是數組~
C. 問大佬php中如何用 foreach解析json
首先,不推薦使用foreach進行自己去解析json字元串,因為php已經封裝了非常好用,且效率不低的內置方法,這個方法就是json_decode。
使用這個函數,可以直接把json數據轉換成數據或者對象,這個是可以控制的。轉換成對象或者數組之後,再使用foreach就可以方便遍歷得到想要的數據。
D. php解析json並輸出到html頁面
用json_decode()將json字元串轉化成php數組,然後直接循環數組取出值即可。
<?php
$content= file_get_contents('獲取json字元串的url');
$content = json_decode($content);//將json字元串轉化成php數組
foreach ($content as $key ) {//循環數組
echo '<li>' . $key['city'] . '</li>';
echo '<li>' . $key['city_en'] . '</li>';
echo '<li>' . $key['date_y'] . '</li>';
echo '<li>' . $key['week'] . '</li>';
}
E. 請問PHP如何解析這樣的json值如何獲取其中某個值內容呢 代碼如下:
PHP裡面有對函數 是轉換JSON為字元串 和JSON轉化為字元串的函數,你定義一個變數=解析(JSON字元串)然後列印一下 取對應的鍵名就可以得到想要的內容了
F. PHP怎麼解析json數據
//使用json_decode函數解碼
$arr=json_decode($json,true);
$number=$arr['number'];
G. php如何解析這樣的json字元串
$jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUCCESS"}}'; $arr = json_decode($jsonStr, true); $payzt = $arr['msg']['payzt']; // 或者 $jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUCCESS"}}'; $arr = json_decode($jsonStr); $payzt = $arr->msg->payzt;
關鍵是對json_decode函數的使用。
H. php解析json問題
$r = json_decode({"code":200,"result":[這里是json數據]});
$r->result 就是你的數據
I. PHP中這個字元串JSON格式嗎應該怎麼解析
php里沒有json格式。。需要decode解析。。encode編碼。另外我是猜的
J. php 解析json 字元串,真的沒人會嗎求大神解答
$a=['2'=>2,'3'=>3,'4'=>json_encode(['5'=>'5','6'=>'6'])];
$b=['a'=>json_encode($a),'b'=>['a'=>'b']];
$json_code=json_encode($b);
echo$json_code;
echo" ";
$json_str='{"a":"{"2":2,"3":3,"4":"{\"5\":\"5\",\"6\":\"6\"}"}","b":{"a":"b"}}';
//這兩個並不相等
var_mp($json_code);
var_mp($json_str);
echo" ";
//這樣才相等
$json_str='{"a":"{"2":2,"3":3,"4":"{\"5\":\"5\",\"6\":\"6\"}"}","b":{"a":"b"}}';
$json_str=str_replace("\\","\\\",$json_str);
echo" ";
echo$json_str;
echo" ";
$arr=json_decode($json_str,true);
print_r($arr);