I'm writing a DataSnap Rest Client (in Delphi) and I want it to provide
data in json format to a lot of platforms (like C#, java, C++, Delphi).
I'm using TJsonMarshal to serialize an object. I'm using something
similar to this:
marshal := TJSONMarshal.Create(TJSONConverter.create);
jsonString := marshal.marshal(myObject).ToString;
But When I do it, the generated JSON is something like this:
{"type":"WJsonObj.TWPedido","id":1,"fields":
{"Numero":1234,"Data":41606.7632623727,"VlrTotal":2543,
"Produtos":
[{"type":"WJsonObj.TWProdutoPedido","id":2,"fields":
{"Codigo":"P001","Descr":"Computador","Qtde":1,"VrUnitario":1500}},
...
{"type":"WJsonObj.TWProdutoPedido","id":4,"fields":
{"Codigo":"P003","Descr":"Projetor","Qtde":1,"VrUnitario":745}}
]
}
}
And I wanted plain JSON, without metadata ('type', 'id' and 'fields'), so I
wouldn't have extra json parsing in non-Delphi platforms. Is there a way
to force the TJsonMarshal to serialize into "plain" JSON?
You should use System.JSON and REST.JSON instead of Data.DBXJson and Data.DBXJSONReflect
var
foo, newfoo: TFoo;
s: string;
foo := TFoo.Create;
s := TJson.ObjectToJsonString(foo);
newfoo := TJson.JsonToObject<TFoo>(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With