I want to clean strings that are retrieved from a database.
I ran into this issue where a property value (a name from a database) had an embedded TAB character, and Chrome gave me an invalid TOKEN error while trying to load the JSON object.
So now, I went to http://www.json.org/ and on the side it has a specification. But I’m having trouble understanding how to write a cleanser using this spec:
string
- “”
- ” chars “
chars
- char
- char chars
char
- any-Unicode-character-
except-“-or–or-
control-character - \”
- \\
- /
- \b
- \f
- \n
- \r
- \t
- \u four-hex-digits
Given a string, how can I “clean” it such that I conform to this spec?
Specifically, I am confused: does the spec allow TAB (0x0900) characters? If so, why did Chrome given an invalid TOKEN error?
This maybe what you are looking for it shows how to use the JavaScriptSerializer class in C#.
How to create JSON String in C#