He aquí un extracto from jQuery 1.9.1:
parseJSON: function(data) {
// Attempt to parse using the native JSON parser first
if (window.JSON && window.JSON.parse) {
return window.JSON.parse(data);
}
if (data === null) {
return data;
}
if (typeof data === "string") {
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim(data);
if (data) {
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if (rvalidchars.test(data.replace(rvalidescape, "@")
.replace(rvalidtokens, "]")
.replace(rvalidbraces, ""))) {
return (new Function("return " + data))();
}
}
}
jQuery.error("Invalid JSON: " + data);
},
Como se puede ver, jQuery utilizará el método nativo JSON.parse
si está disponible, y de lo contrario se tratará de evaluar los datos con new Function
, que es una especie de como eval
.
Así que sí, definitivamente deberías usar jQuery.parseJSON
.
Creo que JSON.parse no está disponible en los navegadores antiguos. En términos de velocidad, deberían ser idénticos, JSON.parse debería ser un poco más rápido (creo que jQuery usa JSON.parse en los navegadores más nuevos). –