How to escape single quotes in generated JSON?

Mariano Martinez Peck <[email protected]>
Newsgroups gmane.comp.lang.smalltalk.squeak.seaside
Message-ID <CAA+-=mWw_bz0QN8B+eNDADVCzvFPK5Mt6VQoApJD+Fm6yppP9g@mail.gmail.com>
Hi guys,

I am trying to serialize a dictionary form Smalltalk with either NeoJSON or
with Seaside's #asJson. Imagine something like this:

| infoDict stream |
stream := String new writeStream.
  infoDict := Dictionary new.
*  infoDict at: 'exception' put: 'a  ''escape this'' aa'.*

Note that the string of 'exception' may contain single quotes inside.

Then, at some point I do:

*self requestContext responseGenerator response nextPutAll: (infoDict
asJson).*


Problem is the string arrives without any escaping so....when I try to do
this at client side from that string:

jQuery.parseJSON(variableContainingThatString);

I get an error as single quotes inside the double quotes do not seem
allowed.
I tried a lot of combinations of *"JSON.stringify*" or things like:

variableContainingThatString*.replace(/[\\"'']/g,
''\\$&'').replace(/\u0000/g, ''\\0''); *

but none work...

So..I wonder...can I simply escape this from server side at the time I
serialize to JSON? Any special way of doing this or I hack on the resulting
string?

Thanks in advance,


-- 
Mariano
http://marianopeck.wordpress.com

_______________________________________________
seaside mailing list
[email protected]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.