addJavascriptInterface

addJavascriptInterface

本文介绍了传递在Android上使用addJavascriptInterface()JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用addJavascriptInterface从JavaScript传递一个JavaScript对象到Java()?这些方针的东西:

Is it possible to pass a JavaScript object from JavaScript to Java using addJavascriptInterface()? Something along these lines:

var javaScriptObject = {"field1":"string1", "field2":"string2"};
JavaScriptInterface.passObject(javaScriptObject);

如何将这样的电话被捕获在Java端?我没有问题建立接口发送一个字符串,但是当我送一个对象,我收到空Java的结束。

How would such a call be captured on the Java side? I have no problem setting up the interface to send a string, but when I send an object, I receive null on the Java end.

推荐答案

AFAIK, addJavascriptInterface()只能用基本类型和字符串的作品,所以你不能传递任意JavaScript对象。

AFAIK, addJavascriptInterface() only works with primitive types and Strings, and so you cannot pass arbitrary Javascript objects.

这篇关于传递在Android上使用addJavascriptInterface()JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 18:09