JSON元帅:是否可以serialize/desrializeinto/from'plain'JSON(没有元数据)?
JSONMarshal: Is it possible to serialize/desrialize into/from 'plain' JSON (without metadata)?
我正在编写一个 DataSnap Rest Client(在 Delphi 中),我希望它提供
json 格式的数据到许多平台(如 C#、java、C++、Delphi)。
我正在使用 TJsonMarshal
来序列化一个对象。我在用东西
与此类似:
marshal := TJSONMarshal.Create(TJSONConverter.create);
jsonString := marshal.marshal(myObject).ToString;
但是当我这样做时,生成的 JSON 是这样的:
{"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}}
]
}
}
我想要纯 JSON,没有元数据('type'
、'id'
和 'fields'
),所以我
在非 Delphi 平台上不会有额外的 json 解析。有没有办法
强制 TJsonMarshal
序列化为 "plain" JSON?
您应该使用 System.JSON
和 REST.JSON
而不是 Data.DBXJson
和 Data.DBXJSONReflect
var
foo, newfoo: TFoo;
s: string;
foo := TFoo.Create;
s := TJson.ObjectToJsonString(foo);
newfoo := TJson.JsonToObject<TFoo>(s);
我正在编写一个 DataSnap Rest Client(在 Delphi 中),我希望它提供
json 格式的数据到许多平台(如 C#、java、C++、Delphi)。
我正在使用 TJsonMarshal
来序列化一个对象。我在用东西
与此类似:
marshal := TJSONMarshal.Create(TJSONConverter.create);
jsonString := marshal.marshal(myObject).ToString;
但是当我这样做时,生成的 JSON 是这样的:
{"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}}
]
}
}
我想要纯 JSON,没有元数据('type'
、'id'
和 'fields'
),所以我
在非 Delphi 平台上不会有额外的 json 解析。有没有办法
强制 TJsonMarshal
序列化为 "plain" JSON?
您应该使用 System.JSON
和 REST.JSON
而不是 Data.DBXJson
和 Data.DBXJSONReflect
var
foo, newfoo: TFoo;
s: string;
foo := TFoo.Create;
s := TJson.ObjectToJsonString(foo);
newfoo := TJson.JsonToObject<TFoo>(s);