How do I handle newlines in JSON?

后端 未结 10 1300
后悔当初
后悔当初 2020-11-22 05:28

I\'ve generated some JSON and I\'m trying to pull it into an object in JavaScript. I keep getting errors. Here\'s what I have:

var data = \'{\"count\" : 1, \         


        
10条回答
  •  情深已故
    2020-11-22 06:13

    You could just escape your string on the server when writing the value of the JSON field and unescape it when retrieving the value in the client browser, for instance.

    The JavaScript implementation of all major browsers have the unescape command.

    Example:

    On the server:

    response.write "{""field1"":""" & escape(RS_Temp("textField")) & """}"
    

    In the browser:

    document.getElementById("text1").value = unescape(jsonObject.field1)
    

提交回复
热议问题