By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,966 Members | 2,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,966 IT Pros & Developers. It's quick & easy.

jason_encode fails with special characters

Claus Mygind
100+
P: 571
I have a user that typed the following into an input field

set 30

This data was stored in the table using software other than php.

Now I am writing some new access code in php and while the data is retrieved from the table correctly, the ajax response returns a null value for that column/field (see photo look for "PRJCTADDR1")

I return a response to the client like so through jason_encode:
echo json_encode($res_array);

The client gets a null value, see attached photo (again look for "PRJCTADDR1".

Is there some standard routine to strip this and other characters from the data stream or otherwise escape these value?

What values should I be on the lookout for?
Attached Images
File Type: jpg degree mark there.jpg (42.5 KB, 147 views)
File Type: jpg degree mark null value.jpg (20.1 KB, 175 views)
Dec 12 '11 #1
Share this Question
Share on Google+
6 Replies


Claus Mygind
100+
P: 571
Just a followup, just to confirm this is a jason_encode problem. Here is the formatted value of the encode.

[{...,"PRJCTNAME":"Proposed Multi-Legged Water Tower","PRJCTADDR1":null,.....}]
Dec 12 '11 #2

Claus Mygind
100+
P: 571
A partial answer is to use htmlentities(string) to encode any string to be included in the json response array. However now I need to decode the result on the client where I now get this answer:

"PRJCTADDR1":"with Legs offset 30º"
Dec 12 '11 #3

Dormilich
Expert Mod 5K+
P: 8,639
you could try urlencode() in PHP and decodeURIComponent() in JS.
Dec 13 '11 #4

Claus Mygind
100+
P: 571
Ah! This is occurring in the response to an ajax call in a simple data field. The "htmlentities(string)" works very well.

But the decodeURIComponent() sounds like a good idea.

Thanks for your response.

BTW, you steered me toward EventBug. Seems to be broken with FireFox 8. You got any alternate ideas to put in another great tool like that?
Dec 13 '11 #5

Dormilich
Expert Mod 5K+
P: 8,639
But the decodeURIComponent() sounds like a good idea.
but it can't unescape entities, only %-escapes

BTW, you steered me toward EventBug. Seems to be broken with FireFox 8. You got any alternate ideas to put in another great tool like that?
I know it's a bother. currently I don't have a replacement. I only can hope that it will be supported in FF 9+
Dec 14 '11 #6

Claus Mygind
100+
P: 571
Ok thanks, I will work on that
Dec 16 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.