Can a json string contain HTML tags with it?

后端 未结 4 1327
别跟我提以往
别跟我提以往 2020-12-30 10:41

Consider this my json string,

[{
  \"Mat_id\": \"2\",
  \"Mat_Name\": \"Steel\",
  \"Measurement\": \"mm\",
  \"Description\": \"Steel\"
}]

相关标签:
4条回答
  • 2020-12-30 11:28

    This answer is for >Angular 2 compilation regarding parsing json containing html tags.

    Below is the json containing html tags

    { 
     "data":"highlighting <b>this</b> in bold"
    }
    

    As you can see this is the keyword need to be bold in html while rendering.

    If I use angular interpolation like below it will be parsed as normal string and <b> tag will be printed as it is.

       <p> {{titleDetails.what}}</p>
    

    output : highlighting <b>this</b> in bold.

    But if you use property binding like below it will render the expected output.

       <p [innerHTML]="titleDetails.what"></p>
    

    Output: highlighting this in bold

    0 讨论(0)
  • 2020-12-30 11:40

    Yeah.. no problem with that. :)

    0 讨论(0)
  • 2020-12-30 11:42

    Technically, yes, you can do that... practically, I'd be a bit concerned if there were HTML markup in my data. What else might be in there? Smells like an XSS vulnerability.

    0 讨论(0)
  • 2020-12-30 11:43

    use Encoder.js from http://code.google.com/p/jsool/source/browse/jsool-site/js/util/Encoder.js?r=176

    when getting data use

    Encoder.htmlDecode(value);

    and when passing data use

    Encoder.htmlDecode(value);

    0 讨论(0)
提交回复
热议问题