onryldz / x-superobject

Delphi Cross Platform Rapid JSON
316 stars 118 forks source link

Unicode issue #94

Open stephanewierzbicki opened 8 years ago

stephanewierzbicki commented 8 years ago

Hello,

I've an issue with accentuated characters. Basically I'm getting such a JSON string :

{"clients":[{"centrale":"INTERNATIONAL","cp":"75017","idClient":20489,"nom":"Paris/Wagram (Dépôt Garges-lès-Gonesse)","ville":"PARIS 17"},{"centrale":"INTERNATIONAL","cp":"75017","idClient":19650,"nom":"Paris/Wagram","ville":"PARIS"}],"taches":[{"contact":"Mr XCD ","date":"2016-04-20T11:53:03.0Z","idClient":18834,"idContact":7248,"idTache":12709,"idType":10,"tache":"Suite Rappeler du 27/01/16.\n\nRappeler le client pour avoir un RDV - Proposition légère, Foire et destockage","termine":false},{"contact":"Mme FG-EER ","date":"2016-04-20T11:25:00.0Z","idClient":6571,"idContact":7636,"idTache":12630,"idType":10,"tache":"Suite Appel du client du 06/04/16.\n\nProposer OP légère. Revient de vacances semaine 16","termine":false}],"contactTypes":[],"contactFonctions":[{"fonction":"Chef","idFonction":1},{"fonction":"Second","idFonction":2}]}

I'm using this string to create my JSON SuperObject :


X := TSuperObject.Create(TJSONRequest(Connection.Requests[0]).Content);

for AMember in X.A['clients'] do
begin
  Showmessage(AMember.ToString);
  Showmessage(AMember.AsObject.S['nom']);
end;

AMember.ToString display {"centrale":"INTERNATIONAL","cp":"75017","idClient":20489,"nom":"Paris/Wagram (D\u00c3\u00a9p\u00c3\u00b4t Garges-l\u00c3\u00a8s-Gonesse)","ville":"PARIS 17"}

While AMember.AsObject.S['nom'] display `'Paris/Wagram (Dépôt Garges-lès-Gonesse)'

but Paris/Wagram (Dépôt Garges-lès-Gonesse) was expected !

It looks like JSON string isn't correctly parsed :

é should be \u00E9 instead of \u00c3 ô should be \u00F4 instead of \u00f4

113Bom commented 7 years ago

I think you have read the output a bit too fast.. "Dépôt" is represented as "D\u00c3\u00a9p\u00c3\u00b4t" That is é is not \u00c3, it is \u00c3\u00a9, and ô is \u00c3\u00b4.

Have a look over here : http://stackoverflow.com/questions/26614323/in-what-world-would-u00c3-u00a9-become-%C3%A9

I think your original Json string is not utf-8 but perhaps windows codepage "something"...

Hope this helps.