single quotes around a number in a JSON string in ZnClient POST body

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

single quotes around a number in a JSON string in ZnClient POST body

Paul DeBruicker
Hi -


I'm trying to get the JSON string

"<prosody rate='-20%'>"

I can't figure out how to get there using NeoJSON, the JSON package, or
the JSON stuff from seaside.


Here are the results I'm getting in Pharo2

        str := String
                streamContents: [ :s |
                        s
                                nextPutAll: '<prosody rate=';
                                nextPut: $';
                                nextPutAll: '-20%';
                                nextPut: $';
                                nextPutAll: '>' ]




NeoJSONWriter toString: str '"<prosody rate=''-20%''>"'

"JSON package"
Json render: str '"<prosody rate=''-20%''>"'

"Javascript-Core"
str asJson '"<prosody rate=''-20%''>"'


When sent via a ZnClient POST the doubled single quotes are included in
the JSON body and misinterpreted by the receiving API.

Does anyone have a suggestion I could try?

Thanks

Paul

Reply | Threaded
Open this post in threaded view
|

Re: single quotes around a number in a JSON string in ZnClient POST body

Sven Van Caekenberghe-2
Paul,

All 3 JSON implementations give the same result, the right one ;-)
You are putting a single quote in your unencoded Smalltalk String.
Embedded single quotes inside a JSON string are not escaped, only the double quote and some others (see http://www.json.org).

After conversion, your string stays the same, except for the surrounding double quotes.

| str|
str := String
                streamContents: [ :s |
                        s
                                nextPutAll: '<prosody rate=';
                                nextPut: $';
                                nextPutAll: '-20%';
                                nextPut: $';
                                nextPutAll: '>' ].

(NeoJSONWriter toString: str) = ($" asString, str, $" asString)  => true

So there is still only one single quote before and after the -20%, which is correct.
Smalltalk just prints it as a double single quote.
Maybe there is a problem on the other end ?
Can you produce a curl call that works ?

HTH,

Sven

PS: It is quite strange that you seem to be passing XML as JSON ;-)


On 18 Jun 2013, at 16:33, Paul DeBruicker <[hidden email]> wrote:

> Hi -
>
>
> I'm trying to get the JSON string
>
> "<prosody rate='-20%'>"
>
> I can't figure out how to get there using NeoJSON, the JSON package, or
> the JSON stuff from seaside.
>
>
> Here are the results I'm getting in Pharo2
>
> str := String
> streamContents: [ :s |
> s
> nextPutAll: '<prosody rate=';
> nextPut: $';
> nextPutAll: '-20%';
> nextPut: $';
> nextPutAll: '>' ]
>
>
>
>
> NeoJSONWriter toString: str '"<prosody rate=''-20%''>"'
>
> "JSON package"
> Json render: str '"<prosody rate=''-20%''>"'
>
> "Javascript-Core"
> str asJson '"<prosody rate=''-20%''>"'
>
>
> When sent via a ZnClient POST the doubled single quotes are included in
> the JSON body and misinterpreted by the receiving API.
>
> Does anyone have a suggestion I could try?
>
> Thanks
>
> Paul


--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org