json parse error with double quotes

前端 未结 9 1173
悲哀的现实
悲哀的现实 2020-12-01 11:38

A double quote even if escaped is throwing parse error.
look at the code below

//parse the json in javascript  
var testJson = \'{\"result\": [\"lunch\",         


        
9条回答
  •  盖世英雄少女心
    2020-12-01 12:10

    Well, finally, JSON's parse uses the same eval, so there's no difference when you give them smth. with incorrect syntax. In this case you have to escape correctly your quotes in php, and then escape them and their escaping slashes with json_encode

    
    
    OUTPUT: "{\"result\": [\"lunch\", \"\\\"Show\\\"\"] }"
    

    This should work on client-side JS (if I've made no typos).

提交回复
热议问题