You are not logged in.
Hi Everyone
I have some issue about JSON data returned from mORMot Service.
I have created a service with mORMot (TCarService.GetData) and
the service is called from Browser Client (AngularJS).
Below is service code
function TCarService.GetData(aSqlText: RawUTF8): RawUTF8;
var
Props : TSQLDBConnectionProperties;
res : ISQLDBRows;
begin
Props := TOleDBMSSQL2012ConnectionProperties.Create('127.0.0.1', 'Car_DB', 'sa', 'password');
try
res := Props.ExecuteInlined(aSqlText, True);
result := res.FetchAllAsJSON(True);
finally
Props.Free;
end;
end;
but the returned JSON result looks like this
{"result":["[
{\"MakeCode\":\"ALFA\"},
{\"MakeCode\":\"ASTO\"},
{\"MakeCode\":\"AUDI\"},
{\"MakeCode\":\"BENT\"},
{\"MakeCode\":\"BMW \"},
{\"MakeCode\":\"CHER\"},
{\"MakeCode\":\"TOYO\"},
{\"MakeCode\":\"VOLK\"},
{\"MakeCode\":\"VOLV\"}
]\n"]}
Is there ways to return as True JSON data not string (with FetchAllAsJSON(True)) ?
or I must remove '"', '\' , '\n' at Client Side.
expected Result like this
{"result":
[
{"MakeCode":"ALFA"},
{"MakeCode":"ASTO"},
{"MakeCode":"AUDI"},
{"MakeCode":"BENT"},
{"MakeCode":"BMW"},
{"MakeCode":"CHER"},
{"MakeCode":"TOYO"},
{"MakeCode":"VOLK"},
{"MakeCode":"VOLV"}
]}
Thank you very much
Offline
Your method returns a RawUTF8, so it returns a JSON string.
Use RawJSON to return some JSON content, without conversion to string.
Online
That works Great! Thank you very much ab.
Offline