我需要在HTML(JSON响应)中转义什么 [英] What do I need to escape in my HTML (JSON response)

查看:76
本文介绍了我需要在HTML(JSON响应)中转义什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSON响应如下:

My JSON response looks like:

{rc: "200", test: "", user: "<div class='sub1'>
                <div class='avatar'>                    
                    <a href='/blah'>blah</a><br />
                    <strong>0</strong>
                </div>
                <div class='sl'>
                    <p>
                        you droppped the ball this time
                    </p>
                </div>
                <div class='clear'>
                </div>                        
            </div>"}

更新

我更新了我的代码以在关键值上加上引号,但仍不起作用:

I updated my code to put quotes on the key values, still doesn't work:

{"rc": "200", "m" : "", "o": "<div class='s1'>
            <div class='avatar'>                    
                <a href='\/asdf'>asdf<\/a><br \/>
                <strong>0<\/strong>
            <\/div>
            <div class='sl'>
                <p>
                    444444444
                <\/p>
            <\/div>
            <div class='clear'>
            <\/div>                        
        <\/div>"}


推荐答案

我使用 jsonlint 来验证您的最新示例,并且换行符是它标记的内容。删除,验证。

I used jsonlint to validate your latest example, and the line breaks are what it flagged. When they were removed, it validated.

{
    "rc": "200",
    "m" : "",
    "o": "<div class='s1'><div class='avatar'><a href='\/asdf'>asdf<\/a><br \/><strong>0<\/strong>      <\/div>    <div class='sl'><p>444444444<\/p><\/div><div class='clear'><\/div><\/div>"
}

这篇关于我需要在HTML(JSON响应)中转义什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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