Android:将html字符串从java传递到javascript

Android:将html字符串从java传递到javascript,javascript,java,android,html,Javascript,Java,Android,Html,我正在构建一个android应用程序,我有一个基于web服务器的php页面,它返回的数据如下 {"categories":[{"id":123,"name":"Category 1","img":""},{"id":12,"name":"Category 2","img":""},{"id":56,"name":"Category 2","img":""}]} 现在我已经设法在java中使用这些数据,并获得了我需要的每个元素。我在中读取了一个模板文件,其代码如下: <a class=bu

我正在构建一个android应用程序,我有一个基于web服务器的php页面,它返回的数据如下

{"categories":[{"id":123,"name":"Category 1","img":""},{"id":12,"name":"Category 2","img":""},{"id":56,"name":"Category 2","img":""}]}
现在我已经设法在java中使用这些数据,并获得了我需要的每个元素。我在中读取了一个模板文件,其代码如下:

<a class=button id="category_id"><img src="img_path"></img>category_name</a>
这是在每个类别的for循环中完成的,现在是一个值字符串:

<a class=button id="123"><img src=""></img>Category 1</a><a class=button id="12"><img src=""></img>Category 2</a><a class=button id="56"><img src=""></img>Category 3</a>
其中.button布局是我的webView上的一个div。 但是我得到了这个错误:

"Uncaught TypeError: Cannot set property 'innerHTML' of null", source: file:///android_asset/www/index.html (32)
这是我的javascript的最后一行,您可以在上面看到。 我所要做的就是从数据中加载一个类别列表,并为每个类别创建一个按钮

谢谢。Josh.

您将按钮布局用作类名(),而不是ID(


也许这就是你想要写的。

精彩的一点,我不敢相信阻止我的代码工作的唯一原因是“.”。:/我已经接受了你的答案,但在我似乎有更多的声誉之前,我不能投票支持你。别担心。很高兴能帮忙:)
function showAndroidCategories() {
            var html = Android.showCategories();
            document.getElementById('.button-layout').innerHTML = html;
        }
"Uncaught TypeError: Cannot set property 'innerHTML' of null", source: file:///android_asset/www/index.html (32)
function showAndroidCategories() {
     var html = Android.showCategories();
     document.getElementById('button-layout').innerHTML = html;
}