Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

utf8 in json

Discussion in 'Scripting' started by radiolobito, Sep 7, 2012.

  1. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    i have this json string (is the part with a problem):

    { "ZonesNames":["Polanco","Condesa - Roma","Del Valle","San Ángel - Pedregal","Satélite"]}

    mi problem is to get this red marked characters to untiy3d... any one can help me, please? if I encode or decode to utf8 i get another errors.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    what errors do you get? it should technically not be a problem as long as the file is properly utf8, chances are that they just don't show cause you didn't provide a font that contains them. unitys inbuilt default arial for example is not ASCII compliant
     
  3. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    this errors is in the character only... if i try to encode in utf8 the generator of the json i get this:
    ["Polanco","Condesa - Roma","Del Valle","San Angel - Pedregal","Sat\u00c3\u00a9lite"]

    but this make an error in the json parser by the "\" character

    if i decode the utf8 i get this:
    ["Polanco","Condesa - Roma","Del Valle","San Angel - Pedregal",null]

    (note that the Á is now an A
     
  4. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    I'm going to take a guess here and suggest that AFTER you encode the string to get:

    ["Polanco","Condesa - Roma","Del Valle","San Angel - Pedregal","Sat\u00c3\u00a9lite"]

    You need to escape the "\" character, probably to a double backslash, like so:

    ["Polanco","Condesa - Roma","Del Valle","San Angel - Pedregal","Sat\\u00c3\\u00a9lite"]

    That should do it for you, if not there is always rolling your own "escape" character sequence to handle this and swap occurances of \ with whichever sequence you desire as a post/pre process on each end.
     
  5. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    Sadly, it dosnt works. When unity3d get the first \ i get the error.