In the JSON you want to create, "registration_ids" is an array of strings. But in your code, you are creating "registration_ids" as an array of objects instead. To get the result you want, between WriteStartArray() and WriteEndOfArray(), you need to get rid of WriteStartObject(), WritePropertyName(''), and WriteEndObject():
wrtString := TStringWriter.Create();
wrtJSON := TJsonTextWriter.Create(wrtString);
try
wrtJSON.Formatting := TJsonFormatting.Indented;
wrtJson.WriteStartObject;
wrtJson.WritePropertyName('registration_ids');
wrtJson.WriteStartArray;
//wrtJson.WriteStartObject; // <--
//wrtJson.WritePropertyName(''); // <--
wrtJson.WriteValue(strToken);
//wrtJson.WriteEndObject; // <--
wrtJson.WriteEndArray;
wrtJson.WritePropertyName('notification');
wrtJSON.WriteStartObject;
wrtJSon.WritePropertyName('title');
wrtJson.WriteValue(edtBaslik.Text);
wrtJson.WritePropertyName('body');
wrtJson.WriteValue(edtMesaj.Text);
wrtJSON.WriteEndObject;
wrtJSON.WriteEndObject;
That said, why are you using TJsonTextWriter at all? This would be much more straight-forward if you used TJSONObject and TJSONArray instead, eg:
uses
..., System.JSON;
var
arr: TJSONArray;
notif, obj: TJSONObject;
strJSON: string;
begin
obj := TJSONObject.Create;
try
arr := TJSONArray.Create;
try
arr.Add(strToken);
obj.AddPair('registration_ids', arr);
except
arr.Free;
raise;
end;
notif := TJSONObject.Create;
try
notif.AddPair('title', 'Hi');
notif.AddPair('body', 'Notification test');
obj.AddPair('notification', notif);
except
notif.Free;
raise;
end;
strJSON := obj.ToJSON; // or, obj.Format
finally
obj.Free;
end;
// use strJSON as needed...
end;