json_decode返回null空問題解決方法
May 26, 2016 am 08:21 AMjson_decode對于英文估計返回都是正常的但有些朋友碰到中文時會就發(fā)現(xiàn)返回為null或空了,下面我來給各位朋友簡單介紹此問題解決方法.
今天在做一個東西的時候需要抓取淘寶的一些數(shù)據(jù),找到了請求的url,返回了一個callback,看了下callback中的參數(shù)是一個對象,通過正則匹配去到了數(shù)組,但是在使用json_decode()轉換的時候返回的是NULL,老郁悶了,前一段時間要做一個東西也是因為這個原因,沒有成功的把json對象轉換成php的數(shù)組,放棄了,今天又遇到了,終于找到了解決的辦法.
原因在于:抓取的數(shù)數(shù)據(jù)是是GBK格式,通過抓包看到,返回的header頭中,代碼如下:
Content-Type:text/html;charset=GBK
這個時候用icvo轉碼下,然后在json_decode()就可以正常轉換了,代碼如下:
iconv('gbk','utf-8',$data[1][0]);
這里還需要主要的是你php代碼文件的格式,建議是utf-8無bom頭.
本文地址:
轉載隨意,但請附上文章地址:-)

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
