You are not logged in.
Pages: 1
Hello,
I have following web service format that I need to prepare for using a rest web service. This is for an online sales portal api. I do not have any chance of having it changed to something else.
"specs":{
"spec":[
{
"@required":"true",
"@value":"Kullanılmış",
"@name":"Durumu"
},
{
"@required":"true",
"@value":"10.0 - 11.9 MP",
"@name":"Çözünürlük (Megapiksel)"
},
{
"@required":"true",
"@value":"Kodak",
"@name":"Marka"
}
]
}
Above is just a part of a bigger json string. I also have some individual usage like:
"photos":{
"photo":{
"@photoId":"0",
"url":"http://images.gittigidiyor.com/2941/KODAK-Z915-10MP-10X-ZOOM-HD-SIFIR-URUN__29416457_0.jpg"
}
}
These are json strings that I need to generate using records. I could not figure a solution myself.
Any help is appreciated.
Thanks & regards,
Ertan
Offline
You could try https://github.com/synopse/mORMot/commi … 69dcdf54b4
It allows to parse identifier as SQL string (e.g. "@field0"), to define the field name of the record as yo expect.
Any feedback is welcome.
Offline
I just need to generate (serialize) json string like in my example for this web service. Responds to requests from the web service seem to be fine (no @ sign in them) as to their documentation.
I maybe wrong. My understanding this commit is for deserialization. It is good to have anyway. Thank you for that.
I’m searching for a solution without manual inserts in json string after serialization. Well, as much as possible of course.
Offline
This commit is to enhance TTextWriter.RegisterCustomJSONSerializerFromText() text definition of the record layout.
You can register your record as such:
type
TMyPhoto = packed record
photoID, uri: RawUTF8;
end;
....
TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TMyPhoto), '"@photoId",uri:RawUTF8');
And it will work automatically for both serialization and deserialization of this record, stand-alone or nested in another record, or any dynamic array of this record.
Offline
Sorry for the mis understanding. After explanations I used following code in an empty project using Delphi:
...
TTest = packed record
abc: string;
end;
const
__TTest = '"@abc" string';
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
SynCommons;
procedure TForm1.Button1Click(Sender: TObject);
var
x: TTest;
Json: RawUTF8;
begin
x.abc := 'here I am';
Json := SynCommons.RecordSaveJSON(x, TypeInfo(TTest));
ShowMessage(string(Json));
end;
initialization
TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TTest), __TTest);
end.
I see displayed message:
{"@abc":"here I am"}
Thanks for the help.
Offline
Pages: 1