In my page I have an applet. I’d like to pass a some data to an applet function. I’ve found out how to do this and it worked fine for simple datatypes like strings but I’m having hard time with some nested data structures. I’m not sure what would be the right term for it — a list of dictionaries or an array of associative arrays. Here’s a snippet of my JavaScript data structure is built.
var servers = []
servers.push({'id' : 1, 'ip' : '111.111.111.111'});
servers.push({'id' : 2, 'ip' : '222.222.222.222'});
$('testapplet').setWork(servers);
How do I access this in Java? I’d like to iterate over them and print them to the console? I tried the following code but I couldn’t get it to work.
public void setWork(HashMap s[]) {
for (int i = 0; i < s.length; i++) {
HashMap item = s[i];
System.out.println(item);
System.out.println(item.get("ip"));
}
}
I’m not sure the Java/JavaScript bridge support anything other than primitive types.
You could try serialising to JSON, then pass that over the bridge:
Edit: as just mentioned… 🙂