Skip to content

Instantly share code, notes, and snippets.

@Alex-Ikanow
Created January 6, 2012 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alex-Ikanow/1571455 to your computer and use it in GitHub Desktop.
Save Alex-Ikanow/1571455 to your computer and use it in GitHub Desktop.
Parsing script to convert internal NativeObjects and NativeArrays to JSON
function s1(el) {
if (el instanceof Array) {
s2(el, 1);
}
else if (typeof el == 'object') {
outList.add(s3(el));
}
else {
outList.add(el);
}
}
function s2(el, master_list) {
var list = (1 == master_list)?outList:listFactory.clone();
for (var i = 0; i < el.length; ++i) {
var subel = el[i];
if (subel instanceof Array) {
list.add(s2(subel, 0));
}
else if (typeof subel == 'object') {
list.add(s3(subel));
}
else {
list.add(subel);
}
}
return list;
}
function s3(el) {
var currObj = objFactory.clone()
for (var prop in el) {
var subel = el[prop];
if (subel instanceof Array) {
currObj.put(prop, s2(subel, 0));
}
else if (typeof subel == 'object') {
currObj.put(prop, s3(subel));
}
else {
currObj.put(prop, subel);
}
}
return currObj;
}
s1(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment