Removing unsafe ascii characters from a string

Word Count: 248

Last night I was working on a Mobile application that gets is data via a web service. This web service returns JSON by turning a record set into JSON using the serlializeJSON() function that is built into ColdFusion.

Whenever I am dealing with JSON I like to validate it before I start using it in an application. A great resource for validating data is http://jsonlint.com/. The data I was trying to get just was not validating and we couldn't figure out why. It seem to keep complaining about the bio of the speaker. This data for this was produced by the end user. In the end Elliott realized that it was unsafe characters in the Bio that was throwing everything off. He used this code to fix the issue and the json was now validating.

I was going to explain how this works but my friend Ben Nadel has a whole post on this you should really check out. Basically all the code above is doing is removing an un safe character that does not fall in between the "safe" ascii codes of 1-127.

Comments

#1 Posted By: Travis Posted On: 8/3/10 3:08 PM
It's important to note in Ben's code that he's also removing some MS "smart" quotes and stuff. In my application I've found I need to remove 17 18 19 20 25 28 29 (this doesn't include the MS elipse) which is in the "safe" range.
#2 Posted By: Dan Vega Posted On: 8/3/10 3:10 PM |
Author Comment
Right, just in my case I didn't want anything breaking json format.


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.