react native中自定义模块能否直接返回JSONObject数据?



  • 错误提示:
    Cannot convert argument of type class org.json.JSONObject
    fromJavaArgs
    Arguments.java:193
    invoke
    CallbackImpl.java:34
    show
    ToastModule.java:39
    invoke
    Method.java
    invoke
    JavaMethodWrapper.java:374
    invoke
    JavaModuleWrapper.java:162
    run
    NativeRunnable.java
    handleCallback

    我自定义模块的源码如下:
    JSONObject ret = new JSONObject();
    try {
    ret.put("status", true);
    } catch (Exception e) {
    e.printStackTrace();
    }
    successCallback.invoke(ret);
    Toast.makeText(getReactApplicationContext(), message, duration).show();
    直接返回的是JSONObject 。这样有问题吗,successCallback具体可以回传那些类型的参数?



  • Android平台的话使用WritableMap发送json对象给js,官方文档有说

    WritableMap writableMap = Arguments.createMap();
    String name = "Tom";
    writableMap.putString("name", name);
    promise.resolve(writableMap)