Javascript JSON.parse(jsonEmText) works on Linux but not on Windows. How to resolve?

Asked

Viewed 147 times

1

Hello, everyone. I have an HTML page that uses Angularjs to display a JSON that is passed by using the encodeURI(). On Linux I can pass this JSON without problems, but when the same page function is done on Windows, it gives formatting error JSON.

The code below is Javascript.

Here I am sending the JSON using the encodeURI().

var modalPath = path.join('file://', __dirname, 'paginas/etiqueta/verEtiqueta.html?ETiqueta=' + encodeURI(objProduto)); var win = new BrowserWindow({ width: screen.width, height: screen.height }); win.on('close', function() { win = null }); win.loadURL(modalPath); win.show();


Here I am getting the JSON by taking the parameter by URL and using decodeURIComponent() for that reason.

var x = location.search.substring(10); var xx = decodeURIComponent(x); var objetoOriginal = JSON.parse(xx);

In linux the variable objetoOriginal receives variable value xx and returns a normal object, whereas in Windows the variable objetoOriginal does not receive value and the console returns format error from JSON. To not leave the question too extensive, I leave the "JSON" that variable xx receives after the decodeURIComponent(x) return the value, result that the variable xx at that link http://pastebin.com/JwnAEqC5

1 answer

0


Good for anyone with this problem the solution is to use the function eval of Avascript, good basically as the JSON that I am going through and very long in some cases the JSON.parse() may not work

// X recebe o JSON da URL cortando fora o inicio que serio o parametro '?Rparametro=' deixando apenas o encodo do JSON

var x = location.search.substring(10); var objetoOriginal = eval('(' + decodeURIComponent(x) + ')');

on the console if we use the command typeof

typeof objetoOriginal returns the type of the variable as an object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.