php JSON解码不起作用(返回null而它是一个有效的JSON)

时间:2014-09-17 10:51:53

标签: php 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)时,它可以正常工作或给出结果。 有什么问题?

3 个答案:

答案 0 :(得分:0)

适合我,你确定$ 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));

答案 1 :(得分:0)

对我而言,它也有效,¿可以检查编码(也许某些角色工作不好)?我正在使用UTF-8

答案 2 :(得分:0)

现在工作正常

我做了什么 -

我在解码JSON之前将其解码为utf-8

     $linked_in=$row['linkedin_profile'];

     $linked=utf8_decode($linked_in);
     $linkedin=json_decode($linked,true);