Android Question [solved] JSON encoding

ALBRECHT

Active Member
Licensed User
Hello,

Please, i have a Json provided from an external DB Table like that :
B4X:
[{"Id":"1","Libelle":"CONFORT ET BIEN-ÊTRE","PictureId":"2428"},
{"Id":"14","Libelle":"AIDES TECHNIQUES","PictureId":"3465"},{"Id":"40","Libelle":"MOBILITE","PictureId":"3464"},{"Id":"53","Libelle":"MATERNITE","PictureId":"3466"},
{"Id":"66","Libelle":"HYGIENE","PictureId":"3452"},{"Id":"79","Libelle":"DIAGNOSTIQUE","PictureId":"4533"},{"Id":"92","Libelle":"PROTECTION","PictureId":"4534"},
{"Id":"105","Libelle":"MATERIEL D’INJECTION","PictureId":"3469"},
{"Id":"32","Libelle":"EQUIPEMENT DE CABINET","PictureId":"4535"},
{"Id":"36","Libelle":"SOINS ET PANSEMENTS","PictureId":"3437"}]

but when i read that with :
B4X:
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim rows As List
rows = parser.NextArray
Thats show me into the listview some special char like : ♦ replacing the accented characters

and if i use the function (readed into the b4x forum):
B4X:
public Sub UnicodeEscape (s As String) As String
    Dim sb As StringBuilder
    sb.Initialize
    For i = 0 To s.Length - 1
        Dim u As String = Bit.ToHexString(Asc(s.CharAt(i)))
        sb.Append("\u")
        For i2 = 1 To 4 - u.Length
            sb.Append("0")
        Next
        sb.Append(u)
    Next
    Return sb.ToString
End Sub
Thats return something like that : \u00xx for each characters into the strings

Should i use a special B4X function to read all kind of international characters
or should i analyse that before the json creation ?

Thank you
Michel
 

hatzisn

Expert
Licensed User
Longtime User
Sorry, just trying to help...
 
Upvote 0

emexes

Expert
Licensed User
What happens if you change the IIS/ASP setting to:

response.Charset = "WTF-2019"

Does IIS give any errors or warnings?

Does it display correctly in a browser?

Does it work in B4A with j.GetString2("ISO-8859-1")?

Does it work in B4A with j.GetString2("UTF-8)?

<JOKE>I wanted to suggest trying response.Charset = "TRUMP-2020" but I didn't want to blow up the forum</JOKE> ;-)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
Yes. See #9.
No. this is the same as j.getstring as B4A is using utf8 by default.
Sorry, I should have directed those questions to the original poster. But I'm glad to receive some answers, even though it's put you above and beyond the call of duty, so: thank you :)

My current assessment, assuming that you set up your local IIS with CharSet = "WTF-2019" or something equally invalid, is that IIS seems to be outputting ISO-8859-1 / windows-1250 regardless of CharSet setting.

In which case Albrecht may as well direct his efforts away from making IIS output UTF-8, and on to less-impossible goals.

:)
 
Upvote 0

emexes

Expert
Licensed User
It sets the content encoding to UTF-8 but the text isn't really encoded with UTF-8
Agreed. Great minds think alike. Well, at least one great mind, and the other's, like, throwing darts blindfolded ;-)

edit: Heck, I though that was a DonManfred post. The above holds true for both, though.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
with that kind of settings before the creation of the Json :
response.ContentType = "application/json"
response.Charset = "UTF-8"
Hey Albrecht, I know I said I was over this, but... I am no good at leaving threads unpulled.

If you still *really* need to use UTF-8, then try using these two settings together:
B4X:
response.CodePage = 65001
response.Charset = "UTF-8"
and then see if the data is encoded and sent using UTF-8, and correctly decoded by:
B4X:
Dim WorksLikeMagic As String = Job.GetString2("UTF-8")
and thus perhaps even by:
B4X:
Dim WorksLikeMagic As String = Job.GetString
 
Upvote 0

ALBRECHT

Active Member
Licensed User
Yesssss,

Thank you very much emexes.

I ve just add the response.CodePage setting to : 65001

I add some chars like : ßñɶϕ

I set : Job.GetString2("UTF-8")

and now its a real UTF-8 with th listview !

Thank you very much.
 
Upvote 0

ALBRECHT

Active Member
Licensed User
please, sould i make someting to close that post or its automaticaly closed or set as resolved ... ?
 
Upvote 0
Top