我尝试在服务器端解析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\":\"\"}
答案 0 :(得分:2)
您的JSON字符串在jsonlint.com验证失败并显示消息
Parse error on line 1:
{ \"id\": \"17\",
-----^
Expecting 'STRING', '}'
如果它不是JSON,则json_decode()
将返回null
如果您首先使用stripslashes()
,则可以对其进行解码。
您使用的是哪个版本的PHP?是否有可能启用魔术引号?
答案 1 :(得分:0)
在每个“之前删除斜杠”并添加到字符串的开头和结尾。它应该看起来像那样
$productInJSON='{"id":"17","img":"CK0092","title":"Серебряное кольцо с гранатом"}';
能够解决您的问题