I can't figure out, why is this not working? Am I missing something obvious?
var doFsu = DOpus.FSUtil;
var doFct = DOpus.Create;
var paths = {
dirs: doFct.Vector,
files: doFct.Vector
}
paths.dirs.push_back('whatever/bogus/path');
var json = JSON.stringify(paths, null, 2);
DOpus.Output('count: ' + paths.dirs.count);
DOpus.Output('dir: ' + paths.dirs(0));
DOpus.Output('paths: ' + paths);
DOpus.Output('json: ' + json);

Notice the empty json string.
Help, please.
Jon
2
The JSON object doesn't know what an Opus Vector object is. You probably need to write a little function to convert the Vector to a JScript array.
1 Like
@Jon thank you.
Although, I'm really confused with this one. The array obviously has the paths in it, but JSON.stringify() outputs them as null... 
var paths = {
dirs: new Array()
}
var counter = 0;
for (var el = new Enumerator(DOpus.listers); !el.atEnd(); el.moveNext()) {
for (var et = new Enumerator(el.item().tabs); !et.atEnd(); et.moveNext()) {
paths.dirs[counter] = et.item().path;
counter++;
}
}
var json = JSON.stringify(paths, null, 2);
DOpus.Output('dirs count: ' + paths.dirs.length);
DOpus.Output('first dir: ' + paths.dirs[0]);
DOpus.Output(json);

Leo
4
It's because JSON also doesn't know what the Opus Path object is or how to convert it into a string.
Change this line:
paths.dirs[counter] = et.item().path;
to this, so it explicitly converts the path to a string before adding it to the array:
paths.dirs[counter] = (et.item().path + "");
1 Like
@Leo thank you.
The gothcas sometimes stumps me for hours on end 
1 Like