La función IsJsonString(str)
, que está usando JSON.parse(str)
, no funciona en mi caso.
Intenté validar la salida json de GraphiQL , siempre devuelve falso. Por suerte, isJSON funciona mejor:
var test = false;
$('body').on('DOMSubtreeModified', '.resultWrap', function() {
if (!test) {
var resultWrap = "{" + $('#graphiql .resultWrap').text().split("{").pop();
if isJSON(resultWrap) {test = !test;}
console.log(resultWrap);
console.log(resultWrap.isJSON());
}
});
Salida de muestra:
THREE.WebGLRenderer 79
draw.js:170 {xxxxxxxxxx
draw.js:170 false
draw.js:170 {xxxxxxxxxx
draw.js:170 false
draw.js:170 {xxxxxxxxxx
draw.js:170 false
draw.js:170 {xxxxxxxxxx
draw.js:170 false
draw.js:170 {
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56, "fps": 41.666666666666664,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56, "fps": 41.666666666666664, "width": 396.984,
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56, "fps": 41.666666666666664, "width": 396.984, "height": 327
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56, "fps": 41.666666666666664, "width": 396.984, "height": 327}
draw.js:170 false
draw.js:170 { "PI": 3.141592653589793, "time": 1570751209006, "tick": 156, "tickr": 1.56, "fps": 41.666666666666664, "width": 396.984, "height": 327}
draw.js:170 true
try
?