“Escape JSON en JavaScript” Código de respuesta

Escape JSON en JavaScript

var myJSONString = JSON.stringify(myJSON);
var myEscapedJSONString = myJSONString.replace(/\\n/g, "\\n")
                                      .replace(/\\'/g, "\\'")
                                      .replace(/\\"/g, '\\"')
                                      .replace(/\\&/g, "\\&")
                                      .replace(/\\r/g, "\\r")
                                      .replace(/\\t/g, "\\t")
                                      .replace(/\\b/g, "\\b")
                                      .replace(/\\f/g, "\\f");
// myEscapedJSONString is now ready to be POST'ed to the server. 
Yawning Yak

JS JSON Escape

JSON.parse(JSON.stringify(jsonObject));
GutoTrosla

Respuestas similares a “Escape JSON en JavaScript”

Preguntas similares a “Escape JSON en JavaScript”

Más respuestas relacionadas con “Escape JSON en JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código