php使用json_decode返回NULL_PHP教程

來源:互聯網
上載者:User
php5.2以後內建json_decode函數,但是對json文本串的格式要求非常嚴格。 很可能使用該函數得到的傳回值是NULL 使用json_last_error()函數擷取到的傳回值是JSON_ERROR_SYNTAX(Syntax error)。 可以通過以下幾個方式排錯。 1. json字串必須以雙引號包含 $output = str_replace("'", '"', $output); 2. json字串必須是utf8編碼$output = iconv('gbk', 'utf8', $output); 3.不能有多餘的逗號 如:[1,2,]用正則替換掉,preg_replace('/,\s*([\]}])/m', '$1', $output)

http://www.bkjia.com/PHPjc/477869.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477869.htmlTechArticlephp5.2以後內建json_decode函數,但是對json文本串的格式要求非常嚴格。 很可能使用該函數得到的傳回值是NULL 使用json_last_error()函數擷取到的返...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.