views:

75

answers:

2

Hi All, I'm passing Data using JSON to iPhone and iPad. One Field of Data is HTML.

The problem is the encoding.

Here's what I get back:

> "GadgetHTML": "<strong>Hello</strong>
> from Catworld<br />\n<img alt=\"\"
> src=\"http://www.iconarchive.com/icons/fasticon/ifunny/128/dog-icon.png\"
> />",

The \ are killing me. The \n does not help.

Any good way to do this?

Any JSON to HTML Cleaning Functions? Encoding?

(There must be something better than manually removing )

Thanks

A: 

The service that sends the JSON Block should escape all back slashes with another backslash.

g.d.d.c
That would change `alt\"` into `alt=\\"` so the data would include a `\` character, then there would be a `"` character which (as it wouldn't be escaped any longer) would terminate the string, so the next character would invalidate the JSON.
David Dorward
Yeah - escaping needed for the wire. Just not after landing on client. But thanks
ActionFactory
We fixed it. How? Switched to 'Touch JSON' Framework - GetAsData...comes in clean an escaped. Nothing else needed. Highly recommend Touch JSON - Thx all
ActionFactory
+1  A: 

It is HTML, it is just JSON encoded. Use a standard JSON parser and the string you get back will have the escape characters handled for you…

… or are you trying to write your own JSON parser? (Probably not a good idea, but if you really want to reinvent the wheel then the spec is at http://json.org (and the ECMA-262 specification would probably help you for the grammar)).

David Dorward
Hi David, Thanks.We are in fact already using the Google JSON Framework...So I thought It should handle the escaping automatically. Seems not the case. Is there some framework Flag I am missing? Some specific 'CleanJSON' call? thx
ActionFactory
We fixed it. How? Switched to 'Touch JSON' Framework - GetAsData...comes in clean an escaped. Nothing else needed. Highly recommend Touch JSON - Thx all
ActionFactory