php JSON解码不起作用(返回null,但它是有效的JSON)


php JSON decoding not working(return null while its a valid JSON)

我有类似的JSON

{"_key":"~","emailAddress":"inezbaranowska@gmail.com","firstName":"Inez","headline":"Business Development Executive at InterContinental Geneva","id":"_qlb1a7SeS","industry":"Hospitality","lastName":"Baranowska","location":{"country":{"code":"ch"},"name":"Geneva Area, Switzerland"},"phoneNumbers":{"_total":1,"values":[{"phoneNumber":"0041 78 615 97 93","phoneType":"mobile"}]},"pictureUrl":"http://m.c.lnkd.licdn.com/mpr/mprx/0_mbFan0ZTKkCkJKytmk9gngI3tTA5Jnytui1lngMYSFLv6-w-GTcGulsslgY7kLrMVF0WYjv","positions":{"_total":1,"values":[{"company":{"id":1112438,"industry":"Hospitality","name":"InterContinental Geneva","size":"201-500 employees","type":"Sole Proprietorship"},"id":494737880,"isCurrent":true,"startDate":{"month":1,"year":2014},"title":"Business Development Executive"}]},"summary":"•'tStrong analytical, problem solving skills and capabilities to look for outside the box solutions obtained through academic achievement and internships in different industries.'n•'tExcellent communication and interpersonal abilities developed through a wide range of experiences from living and working in different countries.'n•'tSelf-confident, like to work in a challenging environment, which requires constant adjustment to new situations"}

当我这样解码时:

$linked_in=$row['linkedin_profile'];
$linkedin=json_decode($linked_in,true);
var_dump($linkedin); 

结果为:NULL。而此代码对于同一列上的其他JSON运行良好。

当我在线解码此JSON时(http://jsonformat.com)它运行良好或产生效果。它有什么问题?

对我来说,它也能工作吗?你能检查编码吗(也许有些字符工作不好)?我使用的是UTF-8

对我有用,你确定$row['linkedin_profile']吗?试试这个代码:

$json = '{"_key":"~","emailAddress":"inezbaranowska@gmail.com","firstName":"Inez","headline":"Business Development Executive at InterContinental Geneva","id":"_qlb1a7SeS","industry":"Hospitality","lastName":"Baranowska","location":{"country":{"code":"ch"},"name":"Geneva Area, Switzerland"},"phoneNumbers":{"_total":1,"values":[{"phoneNumber":"0041 78 615 97 93","phoneType":"mobile"}]},"pictureUrl":"http://m.c.lnkd.licdn.com/mpr/mprx/0_mbFan0ZTKkCkJKytmk9gngI3tTA5Jnytui1lngMYSFLv6-w-GTcGulsslgY7kLrMVF0WYjv","positions":{"_total":1,"values":[{"company":{"id":1112438,"industry":"Hospitality","name":"InterContinental Geneva","size":"201-500 employees","type":"Sole Proprietorship"},"id":494737880,"isCurrent":true,"startDate":{"month":1,"year":2014},"title":"Business Development Executive"}]},"summary":"•'tStrong analytical, problem solving skills and capabilities to look for outside the box solutions obtained through academic achievement and internships in different industries.'n•'tExcellent communication and interpersonal abilities developed through a wide range of experiences from living and working in different countries.'n•'tSelf-confident, like to work in a challenging environment, which requires constant adjustment to new situations"}';
var_dump(json_decode($json, true));

现在运行良好

我做了什么-

在像这样解码JSON之前,我将其解码为utf-8

     $linked_in=$row['linkedin_profile'];
     $linked=utf8_decode($linked_in);
     $linkedin=json_decode($linked,true);