Are multi-line strings allowed in JSON?

前端 未结 9 1326
醉酒成梦
醉酒成梦 2020-11-22 04:21

Is it possible to have multi-line strings in JSON?

It\'s mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I\'m just kinda curious

9条回答
  •  遇见更好的自我
    2020-11-22 04:39

    Try this, it also handles the single quote which is failed to parse by JSON.parse() method and also supports the UTF-8 character code.

        parseJSON = function() {
            var data = {};
            var reader = new FileReader();
            reader.onload = function() {
                try {
                    data = JSON.parse(reader.result.replace(/'/g, "\""));
                } catch (ex) {
                    console.log('error' + ex);
                }
            };
            reader.readAsText(fileSelector_test[0].files[0], 'utf-8');
    }
    

提交回复
热议问题