[Seaside] How to escape single quotes in generated JSON?
Mariano Martinez Peck
marianopeck at gmail.com
Tue Feb 23 16:37:54 UTC 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20160223/57f498ae/attachment.htm
More information about the seaside
mailing list