我有一个很大的问题,通过jQuery Ajax发布数据作为JSON到我的服务器。 JSLint表示数据正常,请求的内容类型设置为application/x-www-form-urlencoded; charset=UTF-8
。服务器运行在PHP 5.2.11上,所以我不能使用json_last_error()
。具有特殊字符的Json_decode
我试过url_decode,utf8_decode和html_entities_decode,但似乎没有任何工作。
var_dump(json_decode($jdata));
返回null,但如果我做了var_dump($jdata)
一切看起来都OK。 $jdata
是发布数据:$jdata = $this->input->post('requestdata');
。
这里是一些例子后的数据从萤火虫抢:
{
"projectnumber": "345",
"projecdescription": "345",
"articles": [
{
"position": 1,
"article_id": 677,
"online_text": "3 Behälter; Band I-III nach indiv. Stückliste, Sprache: DE - Sprache: de"
},
{
"position": 2,
"article_id": 678,
"online_text": "2 Behälter; Band I-III nach indiv. Stückliste, Sprache: ### - Sprache: en"
}
]
}
编辑:
我现在尝试这样做:
$string = $this->input->post('requestdata');
var_dump($string);
$json = preg_replace('/,\s*([\]}])/m', '$1', utf8_encode($string));
$json = json_decode($json);
var_dump($json);
结果是:
字符串( 338)“{”projectnumber“:”4444“,”projecdescription“:” 4444“,”articles“:[{”position“:1,”article_id“:676,”online_text“:”###Behälter;乐队I-III每个人。 Sprache:de“},{”position“:2,”article_id“:681,”online_text“:”###Behälter;乐队I-III每个人。 Stückliste,语言:### - 语言:恩 “}]}” NULL
通过粘贴JSON字符串直接到它的工作原理PHP源代码,而是从后没有得到它!
这会为你工作:http://stackoverflow.com/一个/ 12884807/1226894 – Baba
可能重复[json \ _decode在php中返回null](http://stackoverflow.com/questions/12884802/json-decode-is-returning-null-in-php) – Baba
你确定你在服务器端有一个UTF8字符串?试试'var_dump(json_decode(utf8_encode($ jdata)));' – ThiefMaster