php json轉(zhuǎn)換成字符串的方法:1、使用【json_decode()】函數(shù)對(duì)JSON格式的字符串進(jìn)行編碼;2、使用【json_encode】函數(shù)對(duì)變量進(jìn)行JSON編碼。
推薦:《PHP視頻教程》
php json數(shù)據(jù)轉(zhuǎn)化為字符串
json數(shù)據(jù)本身就是一個(gè)字符串。
如果說轉(zhuǎn)換,只是說,php數(shù)組和json字符串之間的轉(zhuǎn)化,在這里給你介紹php操作json的兩個(gè)函數(shù)
json_decode() 對(duì) JSON 格式的字符串進(jìn)行編碼 說明 mixed json_decode ( string $json [, bool $assoc ] ) 接受一個(gè) JSON 格式的字符串并且把它轉(zhuǎn)換為 PHP 變量 參數(shù) json 待解碼的 json string 格式的字符串。 assoc 當(dāng)該參數(shù)為 TRUE 時(shí),將返回 array 而非 object 。
返回值 Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.
json_encode — 對(duì)變量進(jìn)行 JSON 編碼 Report a bug 說明 string json_encode ( mixed $value [, int $options = 0 ] ) 返回 value 值的 JSON 形式 Report a bug 參數(shù) value 待編碼的 value ,除了resource 類型之外,可以為任何數(shù)據(jù)類型 該函數(shù)只能接受 UTF-8 編碼的數(shù)據(jù)