Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: SOAP and Json


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Oct 11, 2017 12:21 AM Last Post By: Flavio Basile
Flavio Basile

Posts: 83
Registered: 2/17/11
SOAP and Json  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2017 8:17 AM
Hi All,
I have a Soap web service in Delphi. I need to transfer to my client a list of persons in Json format.
This is the simple code that I'm using for generate the Json:
function Tdm1.Get_ListaClienti: TJsonArray;
var aJArray:TJsonArray; aObject, aTmpObject: TJsonObject;
begin
    aJArray:=TJSONArray.Create;
    aObject:=TJSONObject.Create;
    aTmpObject:=TJSONObject.Create;
 
    with quWsClienti do
      begin
          if(Active) then
            close;
          open;
          while(Not(eof)) do
            begin
                aObject:=TJSONObject.Create;
                if(FieldByName('cod_clifor').IsNotNull) then
                  aObject.AddPair(TJsonpair.create('CODICE', FieldByName('cod_clifor').AsString))
                else
                  aObject.AddPair(TJsonpair.create('CODICE', ''));
                if(FieldByName('denominazione').IsNotNull) then
                  aObject.AddPair(TJsonpair.create('RAGIONESOCIALE', FieldByName('denominazione').AsString))
                else
                  aObject.AddPair(TJsonpair.create('CODICE', ''));
                aJArray.AddElement(aObject);
                next;
            end;
      end;
 
   quWsClienti.Close;
 
end;


and this is the code for returning the json as string:
function TPlanetExpose.wspla_Get_Clienti: String;
var aRes:TJsonArray;
begin
   aRes:=dm1.Get_ListaClienti;
   result:=ares.ToString;
 
end;


In this line of code result:=ares.Tostring; I have an access violation in System.json.pas unit.
Someone can help me?
Thanks.
Flavio

Edited by: Flavio Basile on Oct 10, 2017 5:17 PM
Pat Ritchey

Posts: 10
Registered: 3/9/99
Re: SOAP and Json  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2017 9:08 AM   in response to: Flavio Basile in response to: Flavio Basile
The runtime error is because the value of aRes is undefined.

When compiling your data module, you should have seen an warning message something like this:

"Return value of function 'Tdm1.Get_ListaClienti' might be undefined"

You probably need something like:

Result :=  aJArray;


at the end of the Get_ListaClienti function.

--
Pat Ritchey [TeamB Emeritus]
Flavio Basile

Posts: 83
Registered: 2/17/11
Re: SOAP and Json  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 11, 2017 12:21 AM   in response to: Pat Ritchey in response to: Pat Ritchey
Pat, thanks for your reply. When coding and you're tired, you do not see certain things ...
Thanks


Pat Ritchey wrote:
The runtime error is because the value of aRes is undefined.

When compiling your data module, you should have seen an warning message something like this:

"Return value of function 'Tdm1.Get_ListaClienti' might be undefined"

You probably need something like:

Result :=  aJArray;


at the end of the Get_ListaClienti function.

--
Pat Ritchey [TeamB Emeritus]

Edited by: Flavio Basile on Oct 11, 2017 9:21 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02