title: How to pass JSON-formatted data from a WebView to a HTML page
body: <p>I am trying to pass JSON-formatted data from my Android WebView to a HTML page. However, the app crashes whenever I try to parse the original JSON data, which I am expecting to be of the format <code>{"key":"data"}</code></p>
  
  <p>The aim of my app will be to interpret this JSON data, form it into an array of values, and send it to a HTML page. Is this the correct approach to take?</p>
  
  <p>Here is my WebView code...</p>
  
  <pre><code>public class MyWebView extends Activity {
      WebView mWebView;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.web_view);
  
          mWebView = (WebView) findViewById(R.id.webviewSch);
          mWebView.getSettings().setJavaScriptEnabled(true);
          mWebView.addJavascriptInterface(this, "webConnector");
          mWebView.loadUrl("file:///android_asset/table.html");
      }
  
      public String load() {
          return "{\"key\":\"data\"}";
      }
  }
  </code></pre>
  
  <p>And here is the HTML code...</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  
  function loader() {
      var jsonData = window.webConnector.load();
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="loader()"&gt;
  Do nothing
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Here is the log cat:</p>
  
  <pre><code>04-15 00:35:44.551: W/dalvikvm(442): JNI WARNING: jarray 0x4053f1a0 points to non-array object (Ljava/lang/String;)
  04-15 00:35:44.551: I/dalvikvm(442): "WebViewCoreThread" prio=5 tid=9 NATIVE
  04-15 00:35:44.551: I/dalvikvm(442):   | group="main" sCount=0 dsCount=0 obj=0x4051bcc0 self=0x19b200
  04-15 00:35:44.551: I/dalvikvm(442):   | sysTid=451 nice=0 sched=0/0 cgrp=default handle=1684280
  04-15 00:35:44.551: I/dalvikvm(442):   | schedstat=( 206004592 365607782 69 )
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.LoadListener.nativeFinished(Native Method)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.LoadListener.nativeFinished(Native Method)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.LoadListener.tearDown(LoadListener.java:1200)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.LoadListener.handleEndData(LoadListener.java:721)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.LoadListener.handleMessage(LoadListener.java:219)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.os.Handler.dispatchMessage(Handler.java:99)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.os.Looper.loop(Looper.java:130)
  04-15 00:35:44.551: I/dalvikvm(442):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
  04-15 00:35:44.551: I/dalvikvm(442):   at java.lang.Thread.run(Thread.java:1019)
  04-15 00:35:44.551: E/dalvikvm(442): VM aborting
  </code></pre>