Created
January 6, 2012 17:06
-
-
Save Alex-Ikanow/1571455 to your computer and use it in GitHub Desktop.
Parsing script to convert internal NativeObjects and NativeArrays to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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