What do I need to escape in my HTML (JSON response)

后端 未结 4 623
野趣味
野趣味 2021-01-21 01:24

My JSON response looks like:

{rc: \"200\", test: \"\", user: \"
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 01:57

    You're HTML values are OK, but the keys of the JSON object must be enclosed in quotes.

    From the JSON RFC:

    2.2. Objects

    An object structure is represented as a pair of curly brackets
    surrounding zero or more name/value pairs (or members). A name is a
    string.

    and

    2.5. Strings

    The representation of strings is similar to conventions used in the C
    family of programming languages. A string begins and ends with
    quotation marks.

    Also, if you output this JSON object inside the script tags of an HTML page, you must escape the "

提交回复
热议问题