I would like to save my array of objects (arr) into json file from Beckhoff TwinCAT3 using FB_JsonDomParser
. This is what I want to get:
{ 'MyArray' : [{a: 1, b: 0.4}, {a: 3, b: 9.1}, {a: 6, b: 0.1}] }
This is my attempt, where I couldn’t find anything suitable within push methods.
fbJson : FB_JsonDomParser;
jRoot : SJsonValue;
jArrayMain : SJsonValue;
bSaveJsonFile : BOOL;
arr : ARRAY[0..9] OF MYSTRUCT; // structure contains int and real
jRoot := fbJson.NewDocument();
jArray := fbJson.AddArrayMember(jRoot, 'MyArray', 0);
// not sure how to add objects here into jArray
fbJson.SaveDocumentToFile(sFile := 'C:tmptest.json', bExec := bSaveJsonFile);