Is there a way to send a Java array of objects to a JavaScript function?
Here is an example object:
class SitioMapa{
String title;
double lat;
double lng;
String description;
public SitioMapa(String title,double lat,double lng,String description) {
this.title=title;
this.lat=lat;
this.lng=lng;
this.description=description;
}
}
When converted to JSON, it looks like this:
"SitioMapa":[{"title":"Alibaug","lat":"18.641400","lng":"72.872200","description": "Alibaug is a coastal town and a municipal council in Raigad District in the Konkan region of Maharashtra, India."},{...},{...}]
I need to convert a SitioMapa[] array filled with objects like above to a format like:
var markers = [
{
"title": 'Alibaug',
"lat": '18.641400',
"lng": '72.872200',
"description": 'Alibaug is a coastal town and a municipal council in Raigad District in the Konkan region of Maharashtra, India.'
}
,
{
"title": 'Mumbai',
"lat": '18.964700',
"lng": '72.825800',
"description": 'Mumbai formerly Bombay, is the capital city of the Indian state of Maharashtra.'
}
,
{
"title": 'Pune',
"lat": '18.523600',
"lng": '73.847800',
"description": 'Pune is the seventh largest metropolis in India, the second largest in the state of Maharashtra after Mumbai.'
}
];
What is the best way to accomplish this task?
I have tried using JsonObject and JsonArray, but I am still unable to access the data in the array properly.