Hey there,
I'm reciving a JSON from an application. I know the structure, but not the names of the keys. I'm going to extract the URL's, which are placed in the arrays.
But I don't know the names of the key's of the subdocument. So I can't access them like here:
auto ArrayToExtract =MayDocumentView["file"][???];
Using numbers is assuming an offset in an array and no key. It's return value is a
bsoncxx::array::element and not a
document::element.
// My JSON
{
"file": {
"khjasdnkas": ["MyURL_1t", "MyURL_2t", "MyURL_3t"],
"glasdjlasd": ["MyURL_1tp", "MyURL_3tp"]
"more......": [ "... unknown number of elements ..." ]
}
}
If i have the arrays, I know how to extract the elements one by one as a string:
Call: ElementExtract(MaArray[i], &MyString);
int ElementExtract(bsoncxx::document::element eleDUT, std::string * strStringVal){
int iErr = 0;
strStringVal->clear();
if (! eleDUT) {
iErr = 1; // element searched does not exist
} else {
// checking if type correct
if (eleDUT.type() != bsoncxx::types::b_utf8::type_id) {
iErr = 2; // element searched, is found, but has not the right value.
}else{
// Extract the string
strStringVal->append( eleDUT.get_utf8().value.to_string() );
}
}
return iErr;
}