Forum > Android

Deserialize JSON with fpjsonrtti

(1/2) > >>

bsod:
I am a beginner with lamw and i need to deserialize JSON to a Objecj using fpjsonrtti.

But when i use the code below the android app close.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---        LReader := TJSONDeStreamer.Create( nil );    try      LReader.Options := [jdoCaseInsensitive];      LReader.JSONToObject( strJSON {String with JSON data}, FList {Object with TCollection} );    finally      LReader.Free;    end; 
Any suggestions?

dseligo:
Did you create FList somewhere (and free it afterwords)?
Something like:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TYourObject = class(TPersistent) // or something like that......    LReader := TJSONDeStreamer.Create( nil );FList := TYourObject.Create;    try      LReader.Options := [jdoCaseInsensitive];      LReader.JSONToObject( strJSON {String with JSON data}, FList {Object with TCollection} );    finally      LReader.Free;    end;...FList.Free;

bsod:
Hi dseligo,

It seems to me that we cannot create a variable in the private session of TAndroidModule.

If i use a local variable i can deserialize the object.

But I need the FList variable to be accessed in more areas of the code.

dseligo:
By 'TAndroidModule' you mean descendant of the class jForm?
Like this below?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   { TAndroidModule1 }   TAndroidModule1 = class(jForm)
You can have variable in private section (I have it there and it's working).
Maybe you didn't create your form, and you try to use variables in it.

P.S.: I now see that you wrote private session. Did you mean 'section', or session? If later, what do you mean by private session?

bsod:
For example


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   TAndroidModule2 = class(jForm)    btnBuscar: jButton;    procedure btnBuscarClick(Sender: TObject);  private    {private declarations}    FList:TClientes;  public    {public declarations}  end;  procedure TAndroidModule2.AndroidModule2Create(Sender: TObject);begin  FList := TClientes.Create;end; procedure TAndroidModule2.AndroidModule2Destroy(Sender: TObject);begin    FList.Free;  end; procedure TAndroidModule2.btnBuscarClick(Sender: TObject);begin     if not Assigned(FList) then      FList.Create;     LReader := TJSONDeStreamer.Create( nil );    try      LReader.Options := [jdoCaseInsensitive];      LReader.JSONToObject( strJSON {String with JSON data}, FList {FList dont Assigned} );    finally      LReader.Free;    end; end;   

Navigation

[0] Message Index

[#] Next page

Go to full version