@Override
public String JSON2String(JavaScriptObject js) {
// This is a very basic implementation for IE6/IE7 of JSON.stringify
// If many people demand a better one we could consider to use json2.js
// @see https://github.com/douglascrockford/JSON-js/blob/master/json2.js
Properties prop = js.cast();
String ret = "";
for (String k : prop.keys()){
String ky = k.matches("\\d+") ? k : "\"" + k + "\"";
JsCache o = prop.getArray(k).cast();
if (o != null) {
ret += ky + ":[";
for (int i = 0, l = o.length(); i < l ; i++) {
Properties p = o.<JsCache>cast().getJavaScriptObject(i);
if (p != null) {
ret += p.toJsonString() + ",";
} else {
ret += "\"" + o.getString(i) + "\",";
}
}
ret += "],";
} else {
Properties p = prop.getJavaScriptObject(k);
if (p != null) {
ret += ky + ":" + p.toJsonString() + ",";
} else {
ret += ky + ":\"" + prop.getStr(k) + "\",";
}
}
}