私のカスタムメソッド:JSON.parseからの構文エラー()文字列からJSONを取得する
function GetJSON(a) {
if (typeof a !== "string" || !a || a == null) return null;
a = a.replace(/\r\n|\r|\n|\t/g, '').replace(/\\/g, '/');
return new Function("return " + a)();
}
var notes ='{editable:true,useAjax:false,notes:[{"top":76,"left":411,"width":30,"height":30,"text":"hill","editable":true},{"top":183,"left":556,"width":30,"height":30,"text":"lake","editable":true}]}';
return GetJSON(notes); //<-- works fine
//I am trying to replace my custom method with
return JSON.parse(notes);
しかし、私はJSON.parse(呼び出すときに、私は、構文エラーが発生します)
間違っている可能性がありますか?
EDIT: JSON.parse()に渡す実際の値をデバッグ出力から貼り付けました。
今後の参考のために(あなたは構文エラーを受信したときに「何が間違っている可能性があります」)、構文エラーがあなたの入力が構文的に無効であることを意味し、IEそれは言語の文法規則に従っていません。 – Esailija