Java对象数组以Javascript对象数组作为参数

时间:2014-03-05 22:59:39

标签: java javascript arrays json

如何将Java对象数组发送到javascript函数?

这是我的对象

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;       
    }
}

传递给JSon看起来像

"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."},{...},{...}]

我将一个填充了上述对象的SitioMapa []数组发送到javascript中的函数,但是我需要使用conevrt数组中的这个数据呢

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.'
        }
];

我该怎么做?

我已经尝试过JsonObject和JsonArray,但仍然显示像1对象数组这样的参数,无法访问数组中的数据。

1 个答案:

答案 0 :(得分:0)