- Java
Select your favorite languages :
- Or search :
auto x = JSONValue(["age":42, "name":"Bob"]);
"data.json".write(x.toJSON);
Here we can call JSONValue directly on an Associative Array for it is a basic type. Complex structures must define their own serialization process to a tree of JSONValues.
class JsonModel {
// Create Field
int id;
String qrText, licen, trans, name;
// // Constructor
// JsonModel(
// int idInt, String nameString, String userString, String passwordString) {
// // id=idInt;
// // name =nameString;
// // user =userString;
// // password = passwordString;
// }
JsonModel(this.id, this.name, this.licen, this.trans, this.qrText);
JsonModel.fromJson(Map<String, dynamic> parseJSON) {
id = int.parse(parseJSON['id']);
licen = parseJSON['Li
x is a Map
var
str: TMemoryStream;
jss: string;
begin
with TJSONStreamer.Create(nil) do try
str := TMemoryStream.Create;
try
jss := ObjectToJSONString(x);
str.Write(jss[1], length(jss));
str.SaveToFile('data.json');
finally
str.Free;
end;
finally
Free;
end;
end.
TJSONStreamer uses the RTTI so only published x properties are stored.
::serde_json::to_writer(&File::create("data.json")?, &x)?
This requires x to implement Deserialize from serde.
programming-idioms.org