Android Question Problem With Emojis and json_decode

Discussion in 'Android Questions' started by Marcos Alves, May 17, 2018.

  1. Marcos Alves

    Marcos Alves Active Member Licensed User


    I'm getting a problem when using jsonparser fuction as follows:

    - Device A sends data using a POST command to a server, and then the server delivers to device B
    - Suppose that data is an emoji like this: ☺
    - The data is correctly received by the server and stored in mysql database (correctly).
    - When requested by B, the data is codified using json_decode due the presence of other fields for data control, generating something like this:


    - Notice that the field "MSGDATA" is the original emoji correctly codified by json_encode at server side...

    To receive data from server, a POST answer in the side B, using jsonparser, runs the routine:

    Dim Resposta As Map
                                   Resposta = Json1.NextObject
    Dim NewMessage As Map
                                    NewMessage = Resposta.Get(
    Dim IdMessage As String = NewMessage.Get("ID")
    Dim IdChat As String = NewMessage.Get("IDCHAT")
    Dim MsgData As String = NewMessage.Get("MSGDATA")
    Dim MsgCreated As Long = NewMessage.Get("MSGCREATED")
    Dim IdSource As Int = NewMessage.Get("IDSOURCE")

    - Showing MsgData content in a label.text in B side I got u263a (emoji text code!!!) instead of the emoji pic!

    Then, I'm a little confused here. Shouldn't jsonparser had converted the \u263a to ☺ ? What am I doing wrong ?
  2. ronell

    ronell Well-Known Member Licensed User

    take a look at this thread

    then maybe this will work
    Dim MsgData As String = NewMessage.Get("MSGDATA")

    Dim Msg as string


    edittext1.text = UTS(Msg)
    Sub UTS (codepoint As Int) As String
    Dim bc As ByteConverter
    Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
    Return BytesToString(b, 04"UTF32")
    End Sub
  3. Erel

    Erel Administrator Staff Member Licensed User

    Dim json As JSONParser
    Dim m As Map = json.NextObject
    Activity.Title = m.Get("MSGDATA")

    ronell likes this.
  4. Marcos Alves

    Marcos Alves Active Member Licensed User

    Hi @Erel . Fast answering as always. Thanks!
    I understand that I can decode json data came from server but I found a better way... what if all the flow A->server->B could maintain the original Android format, even after successive json encode/decode? If it can be done, it isn't needed to worry with format conversion. I noticed that there are many different notations for json depending on php version, apache, android, ios and so on.

    The problem was in server side notation when I used json_encode in php... something like this:

    $message["MESSARECEIVED"] = $messagefields;

    The solution to maintain recognizable format by Android is to use in server:

    $message["MESSAGERECEIVED"] = $messagefields;

    The options JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES tell to php interpreter to maintain the Android format and then we can storage in mysql using utf8mb4 and send back using echo showing directly in Android without any change!

    I hope that this information could help any other community member that could be having the same issue...
    ronell likes this.
  5. Marcos Alves

    Marcos Alves Active Member Licensed User

    Thanks! I found the solution... please, see my post in this thread.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice