Closed GoogleCodeExporter closed 9 years ago
This issue was closed by revision r67.
Original comment by onryld...@gmail.com
on 23 May 2014 at 3:25
Hello,
I tried exact that with the current version of the xsuperobject (I tried also
the sample-code of the demo1.dpr in the attachment of the issue), but I get the
same error-message. Can you help me? Maybe, a short code-snippet of the usage
with TList or TObjectList?
Thanks!
Original comment by svenbemm...@gmail.com
on 20 Aug 2014 at 10:14
Hello, a simple sample
type
TDetail = class
Name: String;
Size: Double;
end;
TMaster = class
List: TObjectList<TDetail>;
end;
...
var
Test: TMaster;
begin
Test := TMaster.FromJSON('{List: [{Name:"Test Test", Size: 1.82}, {Name:"Foo Foo", Size: 1.72} ]}');
ShowMessage(Test.List[0].Name);
end;
Original comment by onryld...@gmail.com
on 20 Aug 2014 at 10:28
Hi, thanks for the code, in that case it runs, but I tried to generate the JSON
from the object and then regenerate the object from the generated JSON and that
won't run :-(. Here is the code and the generated JSON:
type
TDetail = class
public
Name: String;
Size: Double;
end;
TMaster = class
List: TObjectList<TDetail>;
end;
var
Master: TMaster;
json: string;
Detail:TDetail;
{ TObj }
begin
try
Master:=TMaster.Create;
Detail:=TDetail.Create;
Detail.Name:='Hallo';
Detail.Size:=100;
Master.List:= TObjectList<TDetail>.Create;
Master.List.Add(Detail);
json:=Master.AsJSON;
FreeAndNil(Master);
Master:=TMaster.FromJSON(json); //get an EInvalidCast exception
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
The Value in the json-string-variable is
{"List":{"OwnsObjects":true,"Capacity":1,"Count":1,"List" {"Name":"Hallo","Size":100}],"FOwnsObjects":true,"FItems":[{"Name":"Hallo","Size":100}],"FCount":1,"FArrayManager":{}}}
Thanks for your help!
Original comment by svenbemm...@gmail.com
on 21 Aug 2014 at 7:30
There was an error in the JSON-string, this is the generated string:
{"List":{"OwnsObjects":true,"Capacity":1,"Count":1,"List":[{"Name":"Hallo","Size
":100}],"FOwnsObjects":true,"FItems":[{"Name":"Hallo","Size":100}],"FCount":1,"F
ArrayManager":{}}}
Original comment by svenbemm...@gmail.com
on 21 Aug 2014 at 7:37
Original issue reported on code.google.com by
ros...@gmail.com
on 12 May 2014 at 11:23Attachments: