ericwlange/AndroidJSCore

array in JSObject

krudos opened this issue · 3 comments

i hava a JSObject with a method that return ArrayList<HashMap<String, String>>
but when i call it i get a undefined type
also tried to retur a object [] and get the same error, in ios i can return from a function a nsdictionary or a nsarray with no problem

does androidjscore can handle array or object [] for a JSValue?

i give you a example

test work but
test2, test3 and test4 get a undefined type

@OverRide
public Object test(String query)
{
return "Cheese";
}

@OverRide
public Object test2()
{
return {"Cheese", "Pepperoni", "Black Olives"};

}

@OverRide
public Object test3(String query)
{

    HashMap<String, String> hmap = new HashMap<String, String>();

    hmap.put("data", "Chaitanya");

    return hmap;

}

@OverRide
public Object test4(String query)
{

    HashMap<String, String> hmap = new HashMap<String, String>();

    hmap.put("data", "Chaitanya");

 HashMap<String, String> hmap2 = new HashMap<String, String>();

    hmap2.put("data2", "Chaitanya2");

    return {hmap, hmap2};

}

AndroidJSCore knows how to convert a number of simple types, including strings, integers, doubles, booleans. It doesn't know what to do with complex Java types. In the end, everything must be converted to a JSValue. It looks like you are trying to create dictionaries to pass to JS. To do that, you need to create a JSObject and set its properties. For example, in test4:

public JSValue[] test4()
{
    JSObject foo = new JSObject(context);
    foo.property("data", "Chaitanya");
    JSObject foo2 = new JSObject(context);
    foo2.property("data2", "Chaitanya2");
    return {foo, foo2};
}

This should work, though full disclosure I didn't test this so it may have errors in it.

Please re-open if this doesn't solve your issue.