C/C++ Question ArrayObject* B4RLIB::Function() : how to make this return working ?

candide

Active Member
Licensed User
i have a case where i would like to return from a library function an ArrayObject* of String but i didn't find an example to do that...

only one case seems near what i want, but not with String : ArrayObject* B4RSerializator::ConvertBytesToArray (ArrayByte* Bytes, ArrayObject* Result)

who can help ?
 

candide

Active Member
Licensed User
library : https://github.com/arduino-libraries/Arduino_JSON

i have issue with this function : JSONVar keys() const;
cpp part is :
B4X:
JSONVar JSONVar::keys() const
{
  if (!cJSON_IsObject(_json)) {
    return JSONVar(NULL, NULL);
  }
  int length = cJSON_GetArraySize(_json);
  const char* keys[length];
  cJSON* child = _json->child;
  for (int i = 0; i < length; i++, child = child->next) {
    keys[i] = child->string;
  }
  return JSONVar(cJSON_CreateStringArray(keys, length), NULL);
}
Wrapper should create an ArrayObject with all keys provided by the function
Wrapper in creation but stuck :
B4X:
    ArrayObject* B4RJSONVar::keys()        
    {                                                                                      
       JSONVar jtmp = jsonV.keys();   // create un JSONVar Array with all keys used.(each key is a string)
       int len = jtmp.length();       // read length of array, = nb of Stings  
           
       for (int i = 0;i<len;i++) {               // and read of each string
         ....................wrapPointer(jtmp[i]);  //=> to be added at an ArrayObject
       }     
   Array* arr = ...............................................
        arr->length = .............................................
        arr->data = .......................................
        return arr;
 
Top