A fix using atob() and btoa() functions.
//jsontest3.js //21aug2016 function A(){ this.A=1; this.B= new Uint8Array(16); this.s= new Uint8Array(16); } A.prototype.setup=function(){ var i; for(i=0;i<16;i++)this.B[i]=i; }; function B(){ this.B= 2; // new Uint8Array(16); this.s= 2; //new Uint8Array(16); this.A=1; } var a=new A(); a.setup(); console.log(a); //a fix a.B=btoa(a.B); a.s=btoa(a.s); console.log(a); // var e=JSON.stringify(a); console.log(e); var f=JSON.parse(e); console.log("f= ",f); //a fix f.B=E.toUint8Array(atob(f.B)); f.s=E.toUint8Array(atob(f.s)); console.log("f= ",f); console.log(" "); var b=new B(); console.log(b); var e1=JSON.stringify(b); console.log(e1); var f1=JSON.parse(e1); console.log("f1= ",f1);
The output:
>echo(0); { "A": 1, "B": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), "s": new Uint8Array(16) } { "A": 1, "B": "AAECAwQFBgcICQoLDA0ODw==", "s": "AAAAAAAAAAAAAAAAAAAAAA==" } {"A":1,"B":"AAECAwQFBgcICQoLDA0ODw==","s":"AAAAAAAAAAAAAAAAAAAAAA=="} f= { "A": 1, "B": "AAECAwQFBgcICQoLDA0ODw==", "s": "AAAAAAAAAAAAAAAAAAAAAA==" } f= { "A": 1, "B": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), "s": new Uint8Array(16) } { "B": 2, "s": 2, "A": 1 } {"B":2,"s":2,"A":1} f1= { "B": 2, "s": 2, "A": 1 }
1 Attachment
@ClearMemory041063 started
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.
A fix using atob() and btoa() functions.
The output:
1 Attachment