-1

我尝试在服务器端解析 json 字符串:

$productInJSON = iconv("UTF-8", "windows-1251", $_POST['productInJSON']);
$data = json_decode($productInJSON,true);
echo "<PRE>";
var_dump($data);

结果:

<PRE>NULL

$productInJSON:

{\"id\":\"17\",\"img\":\"CK0092\",\"title\":\"Серебряное кольцо с гранатом\",\"product\":\"СК0092\",\"size\":\"15,5\",\"size1\":\"\",\"size2\":\"\",\"size3\":\"\",\"size4\":\"\",\"dopInfo\":\"Поверхность изделия обработана нанесением тонкого слоя родия (толщиной 0,1—25 мкм) для повышения отражательной способности, коррозионной стойкости, жаростойкости, обеспечения защитно-декоративных свойств. Под заказ все размеры. Под заказ простое серебрение (нанесение тонкого слоя серебра 999° на поверхность изделия) для обеспечение естественного серебряного цвета.\",\"cost\":\"337\",\"cost1\":\"0\",\"cost2\":\"0\",\"cost3\":\"0\",\"cost4\":\"0\",\"discountSite\":\"15\",\"discountShop\":\"10\",\"metal\":\"Серебро\",\"weight\":\"1,80\",\"weight1\":\"\",\"weight2\":\"\",\"weight3\":\"\",\"weight4\":\"\",\"stone1name\":\"Гранат\",\"stone1ID\":\"14\",\"stone1Number\":\"1\",\"stone1Color\":\"Красный\",\"stone1Purity\":\"\",\"stone1Weight\":\"0,55\",\"stone1Shape\":\"Клуглая\",\"stone2name\":\"\",\"stone2ID\":\"0\",\"stone2Number\":\"\",\"stone2Color\":\"\",\"stone2Purity\":\"\",\"stone2Weight\":\"\",\"stone2Shape\":\"\",\"stone3name\":\"\",\"stone3ID\":\"0\",\"stone3Number\":\"\",\"stone3Color\":\"\",\"stone3Purity\":\"\",\"stone3Weight\":\"\",\"stone3Shape\":\"\",\"stone4name\":\"\",\"stone4ID\":\"0\",\"stone4Number\":\"\",\"stone4Color\":\"\",\"stone4Purity\":\"\",\"stone4Weight\":\"\",\"stone4Shape\":\"\",\"stone5name\":\"\",\"stone5ID\":\"0\",\"stone5Number\":\"\",\"stone5Color\":\"\",\"stone5Purity\":\"\",\"stone5Weight\":\"\",\"stone5Shape\":\"\",\"set1ID\":\"18\",\"set2ID\":\"0\",\"set3ID\":\"0\",\"note1ID\":\"0\",\"cat\":\"1\",\"theme\":\"0\",\"order\":\"0\",\"mail\":\"mouse_2.4.7@mail.ru\",\"giftImg\":\"\",\"giftText\":\"\"}
4

2 回答 2

2

您的 JSON 字符串在jsonlint.com验证失败并显示消息

Parse error on line 1:
{    \"id\": \"17\",    
-----^
Expecting 'STRING', '}'

如果不是 JSON,则json_decode()返回 null

如果您stripslashes()先使用它,则可以对其进行解码。

您使用的是什么版本的 PHP?有没有可能你打开了魔术引号?

于 2013-09-18T03:06:00.643 回答
0

删除每个 " 之前的斜线并将 ' 添加到字符串的开头和结尾。它应该看起来像这样

$productInJSON='{"id":"17","img":"CK0092","title":"Серебряное кольцо с гранатом"}';

为了能够解决您的问题

于 2013-09-18T03:56:47.703 回答