danieleteti / delphimvcframework

DMVCFramework (for short) is a popular and powerful framework for WEB API in Delphi. Supports RESTful and JSON-RPC WEB APIs development.
Apache License 2.0
1.21k stars 346 forks source link

JsonToDataset error #726

Closed RDP1974 closed 5 months ago

RDP1974 commented 6 months ago

I'm trying to convert a json string to a fdmemtable

function JsonToMemTable(const S: string): TFDMemTable;
var
  lSer: TMVCJsonDataObjectsSerializer;
  lJsn: TJDOJsonObject;
begin
  Result := TFDMemTable.Create(nil);
  lJsn := StrToJSONObject(S);
  lSer := TMVCJsonDataObjectsSerializer.Create;
  try
    lSer.JsonObjectToDataSet(lJsn, Result, [], TMVCNameCase.ncLowerCase);
  finally
    lSer.Free;
    lJsn.Free; // testare
  end;
end;

I get error there: (invalid character in string at 1,339)

function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject;
begin
  Result := MVCFramework.Utils.StrToJSONObject(aString, ARaiseExceptionOnError);
end;

however the string is correct JSON and works fine with other serializer tested how to solve?

danieleteti commented 6 months ago

Can you provide a reproducible example? Also, the dataset structure but be defined before load JSON. If you want to create structure too you need to use metadata JSON.

Il gio 11 gen 2024, 21:52 Roberto Della Pasqua @.***> ha scritto:

I'm trying to convert a json string to a fdmemtable

function JsonToMemTable(const S: string): TFDMemTable; var lSer: TMVCJsonDataObjectsSerializer; lJsn: TJDOJsonObject; begin Result := TFDMemTable.Create(nil); lJsn := StrToJSONObject(S); lSer := TMVCJsonDataObjectsSerializer.Create; try lSer.JsonObjectToDataSet(lJsn, Result, [], TMVCNameCase.ncLowerCase); finally lSer.Free; lJsn.Free; // testare end; end;

I get error there: (invalid character in string at 1,339) function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject; begin Result := MVCFramework.Utils.StrToJSONObject(aString, ARaiseExceptionOnError); end;

however the string is correct JSON and works fine with other serializer tested how to solve?

— Reply to this email directly, view it on GitHub https://github.com/danieleteti/delphimvcframework/issues/726, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK4ZJHKMJPSBKNF2XUA3WDYOBGJZAVCNFSM6AAAAABBXDUFAWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3TONJWGUYTKOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>