Reputation:
I want to create this JSON text with Delphi IDE:
{
"uygulamaninAdi": "ZGVuZW1l",
"uygulamaninSurumu1": "1",
"uygulamaninSurumu2": "0",
"uygulamaninSurumu3": "0",
"uygulamaninSurumu4": "0",
"uygulamaninMimarisi": "1",
"calistirilmaDuzeyi": "1",
"mesajGonderebilmeDurumu": "1",
"konum": "RDpcUHJvZ3JhbWxhbWE="
}
Here are my codes:
procedure TfrmManifestDosyasiOlusturucu.btnOluşturClick(Sender: TObject);
begin
jsGönderilecekMesaj := TJSONObject.Create;
jsGönderilecekMesaj.AddPair('uygulamaninAdi', TNetEncoding.Base64.Encode(edUygulamanınAdı.Text));
jsGönderilecekMesaj.AddPair('uygulamaninSurumu1', edUygulamanınSürümü1.Text);
jsGönderilecekMesaj.AddPair('uygulamaninSurumu2', edUygulamanınSürümü2.Text);
jsGönderilecekMesaj.AddPair('uygulamaninSurumu3', edUygulamanınSürümü3.Text);
jsGönderilecekMesaj.AddPair('uygulamaninSurumu4', edUygulamanınSürümü4.Text);
jsGönderilecekMesaj.AddPair('uygulamaninMimarisi', IntToStr(cbUygulamanınMimarisi.ItemIndex));
jsGönderilecekMesaj.AddPair('calistirilmaDuzeyi', IntToStr(cbÇalıştırılmaDüzeyi.ItemIndex));
jsGönderilecekMesaj.AddPair('mesajGonderebilmeDurumu', IntToStr(cbMesajGönderebilmeDurumu.ItemIndex));
jsGönderilecekMesaj.AddPair('konum', TNetEncoding.Base64.Encode(edManifestDosyasınınOluşturulacağıKonum.Text));
strKomutSatırıParametreleri := '/olustur ' + jsGönderilecekMesaj.ToString;
ShellExecute(0, 'open', 'bin\Manifest Dosyası Oluşturucu (Yardımcı Uygulama).exe', PWideChar(strKomutSatırıParametreleri), nil, SW_HIDE);
end;
But the problem is the Delphi IDE creates this:
{uygulamaninAdi:ZGVuZW1l,uygulamaninSurumu1:1,uygulamaninSurumu2:0,uygulamaninSurumu3:0,uygulamaninSurumu4:0,uygulamaninMimarisi:1,calistirilmaDuzeyi:1,mesajGonderebilmeDurumu:1,konum:RDpcUHJvZ3JhbWxhbWE=}
As far as I know all of keys should be nested with quotes and all of string values should be nested be quotes.
How can I fix my problem?
Upvotes: 0
Views: 594
Reputation: 595320
Try using TJSONObject.ToJSON
instead of TNSONObject.ToString
.
Also, JSON really isn't well-suited for passing around on the command line. If the target program expects to receive the JSON as a single parameter, and since the JSON has quotes in it and potentially also spaces, you should use AnsiQuotedStr()
to add quotes around, and to escape quotes inside, of the JSON string.
Upvotes: 1