Using var aJS = E.toJS({txt : "012345\nabcde\näöüß"}) instead does exactly the same.
Is your transfer function really:
transfer = function (saJS5) {
var aJS5;
try {
aJS5 = eval('('+saJS5+')');
} catch(e){
console.log("error in eval:",e);
}
}
If so then the issue is that in transfer you're trying to evaluate something that isn't a string. It's already a properly decoded JSON object.
So...
transfer = function (saJS5) {
var aJS5;
try {
aJS5 = eval('('+saJS5+')');
} catch(e){
console.log("error in eval:",e);
}
}
// What you think you're doing
transfer("{txt:\"012345\\nabcde\\n\\xE4\\xF6\\xFC\\xDF\"}") // ok
// what you were doing just by adding '' around a string
transfer('{"txt":"012345\nabcde\n\u00E4\u00F6\u00FC\u00DF"}') // error
// what you're actually doing
transfer({"txt":"012345\nabcde\n\u00E4\u00F6\u00FC\u00DF"}) // error
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I don't understand. I ran this on a Pixl, talking to a Puck.js, and it works great using
print
:Reports:
Using
var aJS = E.toJS({txt : "012345\nabcde\näöüß"})
instead does exactly the same.Is your
transfer
function really:If so then the issue is that in
transfer
you're trying to evaluate something that isn't a string. It's already a properly decoded JSON object.So...