I have javascript code and objects in it, I need to collect those objects and serialize them into array. I use such function:
function getData () {
var objects = [];
for (var i in this) {
if (this[i] instanceof Object)
if (this[i].isShow())
objects.push(JSON.stringify(this[i]));
}
JSInterface.setLocationsData(locations);
}
Then I need to parse this in Java. I get following:
{"title":"sample1", value:1}, {"title":"sample2", value:2}
How do I parse it? It’s not an JSONArray, so I added:
JSInterface.setLocationsData("["+locations+"]");
Any better solution?
Put the stringify on the last line: