Hello, I'm trying to insert strings to my json data.
JObject.Objects['3'].Add('album', 'Album 3'); line is giving me error:
Invalid typcast. Here's my code.
try
begin // this is only a minimal sampling of what can be done with this API
// create from string
JData:=GetJSON('{ "1": {' +
'"album": "Test Album 1",' +
'"artist": "Test Singer 1",' +
'"bpm": 120,' +
'"duration": 180,' +
'"is_enabled": true,' +
'"key": "A",' +
'"num_played": 0,' +
'"path": "/home/user/Desktop/akustik/cem_adrian___sen_benim_sarkilarimsin.mp3",' +
'"played_at": "01.01.2000",' +
'"stars": 5,' +
'"title": "Test \u015eark\u0131s\u0131",' +
'"year": 1999' +
'},' +
'"2": {' +
'"album": "Test Album 2",' +
'"artist": "Test Singer 2",' +
'"bpm": 120,' +
'"duration": 180,' +
'"is_enabled": true,' +
'"key": "A",' +
'"num_played": 0,' +
'"path": "/home/user/Desktop/akustik/cem_adrian___sen_benim_sarkilarimsin.mp3",' +
'"played_at": "01.01.2000",' +
'"stars": 5,' +
'"title": "Test \u015eark\u0131s\u0131",' +
'"year": 1999' +
'}}');
// output as a flat string
StrPtr^:=JData.AsJSON;
// output as nicely formatted JSON
StrPtr^:=JData.FormatJSON;
// cast as TJSONObject to make access easier
JObject:=JData as TJSONObject;
// retrieve value of Fld1
// StrPtr^:=JObject.Get('title');
// change value of Fld2
JObject.Objects['2'].Strings['album']:='Album 2';
// retrieve the second color
// StrPtr^:=JData.FindPath('Colors[1]').AsString;
// add a new element
JObject.Add('3');
JObject.Objects['3'].Add('album', 'Album 3');
How can I add some strings to Json?