JSON.stringify() and char code 128

Posted on
  • How should this be coded?

    currency_symbol =  "€";
    console.log(JSON.stringify(currency_symb­ol));
    // "\u00E2\u0082\u00AC"
    
    currency_symbol =  String.fromCharCode(128);
    console.log(JSON.stringify(currency_symb­ol));
    // "\u0080"
    
  • Looks like 128: € is treated special, because 129 : 0xfc : ü works.

    ue = "ü";
    console.log(JSON.stringify(ue));
    // "\u00FC"
    
  • Yes, it's a hack to allow unicode on Espruino (where it isn't natively supported). The IDE detects unicode, does the conversion, and uploads pre-converted code.

    I think the issue you have is that the Euro symbol isn't actually part of the 0-255 character range: https://en.wikipedia.org/wiki/Euro_sign

    I guess in an ideal world that hack in the IDE would be configurable - you could choose if you wanted UTF8 encoding, or ISO10646-1, or something else.

    For now I'd manually specify it - either fromCharCode as you have done, or \x80

  • Thanks, that is exactly what I am using now.

          ....
          currency_symbol: "\x80",
          ....
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

JSON.stringify() and char code 128

Posted by Avatar for MaBe @MaBe

Actions