I'm serializing JSON with JavaScriptSerializer.Serialize(obj) on a web site with .NET 4.0.30319 and MVC 4.
The problem is that on the prod environment with the same .NET version characters like U+2028 (line separator) or U+2029 do not get escaped to \u2028 or \u2029 as they should when serialized by .NET. The crazy thing is that locally on my environment .NET
escapes them perfectly from the character itself to \u2028 or \u2029. If those characters don't get escaped (link), they break the JavaScript:
Uncaught SyntaxError: Unexpected token ILLEGAL
It's the same code and data I'm running on both environments. The page encoding is UTF-8.
I see that for .NET 4.5.1 this characters are checked (link).
What could be causing that the character doesn't get return escaped? ISS reencoding it?
None
0 Points
1 Post
JavaScriptSerializer not always returning special unicode characters like U+2028 inside JSON esca...
Jun 19, 2014 10:01 AM|tatagonzalez|LINK
Hi,
I'm serializing JSON with JavaScriptSerializer.Serialize(obj) on a web site with .NET 4.0.30319 and MVC 4.
The problem is that on the prod environment with the same .NET version characters like U+2028 (line separator) or U+2029 do not get escaped to \u2028 or \u2029 as they should when serialized by .NET. The crazy thing is that locally on my environment .NET escapes them perfectly from the character itself to \u2028 or \u2029. If those characters don't get escaped (link), they break the JavaScript:
Uncaught SyntaxError: Unexpected token ILLEGAL
It's the same code and data I'm running on both environments. The page encoding is UTF-8.
I see that for .NET 4.5.1 this characters are checked (link).
What could be causing that the character doesn't get return escaped? ISS reencoding it?
Thanks!
javascript asp.net json
Participant
1306 Points
174 Posts
Re: JavaScriptSerializer not always returning special unicode characters like U+2028 inside JSON...
Jun 20, 2014 06:04 AM|George Qiao|LINK
Hi Tatagonzalez,
Thanks for your post.
I think this issue be fixed in .NET 4.5.1, please set it in your project.
javascript asp.net json