I got a big problem posting data via jQuery Ajax as JSON to my Server. JSLint say the data is OK and the Content-Type of the request is set to application/x-www-form-urlencoded; charset=UTF-8
. Server runs on PHP 5.2.11 so I can't use json_last_error()
.
I tried url_decode, utf8_decode and html_entities_decode, but nothing seems to work.
var_dump(json_decode($jdata));
returns null, but if I do a var_dump($jdata)
everything looks OK. $jdata
is the post data:$jdata = $this->input->post('requestdata');
.
Here some example post data grab from Firebug:
{
"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"
}
]
}
Edit:
I tried this now:
$string = $this->input->post('requestdata');
var_dump($string);
$json = preg_replace('/,s*([]}])/m', '$1', utf8_encode($string));
$json = json_decode($json);
var_dump($json);
The result is:
string(338) "{"projectnumber": "4444", "projecdescription": "4444", "articles": [{"position":1, "article_id": 676, "online_text": "### Beh?lter; Band I-III nach indiv. Stückliste, Sprache: DE
- Sprache: de"}, {"position":2, "article_id": 681, "online_text": "### Beh?lter; Band I-III nach indiv. Stückliste, Sprache: ###
- Sprache: en"}]}"
NULL
By pasting the JSON string direct into the PHP source it works, but getting it from post not!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…