Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cometd allow you to publish arrays through JavaScript?

I have this JavaScript code:

$.cometd.publish('/service/slideshow/add_ids', {"list":[1889, 1888, 1887, 1886, 1885, 1884]});

In my Java code I have:

         Map<String,Object> data = message.getDataAsMap();
        if(data.containsKey("list"))
        {
            JSONObject o1 = new JSONObject(data);
            String idList = o1.toString();
        }

and my string 'idList' ends up being:

{"list":"[Ljava.lang.Object;@41c271b8"}

I have successfully published non-arrays and parsed them out correctly, but I can't seem to get arrays to work. Am I doing something wrong? Or is it not supported?

Thanks in Advance.

like image 381
Michael Wildermuth Avatar asked Jun 01 '26 03:06

Michael Wildermuth


1 Answers

Try using JSONArray instead.

Map<String, Object> data = message.getDataAsMap();
if(data.containsKey("list"))
{
    JSONArray ja = new JSONArray(data.get("list"));
    String idList = ja.toString();
}
like image 188
Ravi K Thapliyal Avatar answered Jun 02 '26 15:06

Ravi K Thapliyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!