更新时间:2023-11-16 13:54:22
PluginResult 类是你的朋友:
public PluginResult(Status status, JSONObject message) {
this.status = status.ordinal();
this.message = (message != null) ? message.toString(): "null";
}
或
public PluginResult(Status status, String message) {
this.status = status.ordinal();
this.message = JSONObject.quote(message);
}
在你的情况下,它可以接受JSON对象或一个字符串。因此,要回报你需要一个JSON数组
In your case it accepts either a json object or a string. So to return a json array you need
JSONObject json = new JSONObject();
json.put("foo", "bar");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, json));