使用JSON传递HTML [英] Passing HTML using JSON

查看:607
本文介绍了使用JSON传递HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSON传递数据到iPhone和iPad。
一个数据字段是HTML。



问题是编码。



这是我的回来:

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

\杀死我。
\\\
没有帮助。



有什么好办法吗?



任何JSON到HTML清理功能?
编码?



(必须比手动删除更好)



谢谢

解决方案

这是HTML,它只是JSON编码。使用标准的JSON解析器,您将返回的字符串将为您处理的转义字符...



...或者您是否正在编写自己的JSON解析器? (可能不是一个好主意,但如果你真的想重新发明,那么这个规范在 http://json.org (和ECMA-262规范可能会帮助你的语法))。


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

解决方案

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)).

这篇关于使用JSON传递HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆