1

I have a struct I want to fill with Data from a JSON File with Arduinojson library. Filling the trackCount is no problem. Filling the tracks[] array is where I stuck. Struct:

struct AudioObject {
 byte trackCount;
 const char* tracks[];};

in setup():

AudioObject aO;
getAudioObject(jsonConfigFilename, &foo, &aO);

in function getAudioObject(const char* pConfigFilename, const String *paoID, AudioObject *aO):

    File configFile = SD.open(pConfigFilename);
    DynamicJsonDocument configDoc(4096);
    DeserializationError error = deserializeJson(configDoc, configFile);

    JsonArray arAudio= configDoc["toc"]["audioObject"];
    for(JsonObject audioObject: arAudio)    {
        if(audioObject["audioId"]==*paoID){
            //Found Audio ID Creating Object
            aO->trackCount=(byte)audioObject["trackCount"];
            //Now, lets get the Filenames
            JsonArray arAudioTracks = audioObject["tracks"];
            Serial.println (aO->trackCount);

            //copy the Jsonarray to the AudioObject Array
            copyArray(arAudioTracks,aO->tracks); // <---does not work

         
            configDoc.clear();
            configFile.close();
            return true;

What am I doing wrong? I just want that aO->tracks contains the tracks stored in the jsonArray. Content is: ["filename1.mp3","filename2.mp3",...]

  • It's difficult to say what you're doing wrong when you haven't shared the code you wrote for `copyArray()`. – romkey Oct 25 '20 at 16:59
  • Thanks for responding. I didn't write that function. Copyarray() is a function to copy a Jasonarray into a regular array. See https://arduinojson.org/v6/api/misc/copyarray/ It seems to work if I declare an array like const char* arrMyArray [2] and set ist as destination array. But aO->tracks does not work. I think I don't access the pointer correct but I really don't know how to do it right – user2110946 Oct 25 '20 at 20:57

0 Answers0