How do I handle newlines in JSON?

后端 未结 10 1629
后悔当初
后悔当初 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 05:54

    well, it is not really necessary to create a function for this when it can be done simply with 1 CSS class.

    just wrap your text around this class and see the magic :D

     

    my json text goes here \n\n

    note: because you will always present your text in frontend with HTML you can add the style={{whiteSpace: 'pre-line'}} to any tag, not just the p tag.

提交回复
热议问题