#1 2013-03-04 22:47:13

sjerinic
Member
Registered: 2013-02-11
Posts: 51

Error in JSONToDataSet

Hello,

In database we have test company with Serbian Latin and Cyrillic letters "Test Company ŠČĆ ШЛЧ".

When I try to move data received from Database into TDataSet, Serbian Latin and Cyrillic letters changed.

Here is code.

fTableJSON := FormDataModule.Service.GetCompanyList(FormDataModule.User.CompanyID);  //"Test Company ŠČĆ ШЛЧ" ' It is OK!
fDataSet := JSONToDataSet(self, fTableJSON);

unit mORMot

constructor TSQLTableJSON.Create(const Tables: array of TClass; const aSQL,
  aJSON: RawUTF8);
var len: integer;
begin
  len := length(aJSON);
  PrivateCopyChanged(pointer(aJSON),len);                                                  //"Test Company ŠČĆ ШЛЧ" ' Until here is OK!
  Create(Tables,aSQL,pointer(fPrivateCopy),len);
end;

constructor TSQLTableJSON.Create(const Tables: array of TClass;                   //Here JSONBuffer is "Test Company ŠČĆ ШЛЧ"
  const aSQL: RawUTF8; JSONBuffer: PUTF8Char; JSONBufferLen: integer);
begin // don't raise exception on error parsing
  inherited Create(Tables,aSQL);
  ParseAndConvert(JSONBuffer,JSONBufferLen);
end;

How can I avoid this problem?

Offline

#2 2013-03-05 07:40:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Error in JSONToDataSet

Which version of Delphi are you using?
Are you sure your JSON content is UTF-8 encoded, as expected by the framework?

Read the "Unicode and UTF-8" paragraph in the "SynCommons unit" chapter of the SAD pdf - in revision 1.18.

Offline

#3 2013-03-05 09:18:06

sjerinic
Member
Registered: 2013-02-11
Posts: 51

Re: Error in JSONToDataSet

Delphi XE3.

For my case, I found working around solution. Instead TDataSet I used TSQLTableJSON and everything is working fine.

On server side I put data from SQLServer into RawJSON, and on Client side receive data into RawUTF8. This part shows data correctly. Now if I RawUTF8 data move to:
1. TSQLTableJSON and fill ComboBox with it, everything is OK, but if I put data into
2. TDataSet  and fill ComboBox with it, for each Cyrillic letters I'll get sign "?".

TSQLTableJSON filled: fData := TSQLTableJSON.Create([], '', fTableJSON);
TDataSet filled: fDataSet := JSONToDataSet(self, fTableJSON);

var declaration is:

var
  fTableJSON: RawUTF8;
  fData: TSQLTableJSON;
  fDataSet: TDataSet;

How I sow, problem is on second constructor and Pointer: "JSONBuffer: PUTF8Char"

Offline

Board footer

Powered by FluxBB