title: Gson turn an array of data objects into json - Android
body: <p>Currently I am working on a native android app with webView front end.</p>
  
  <p>I have something like:</p>
  
  <pre><code>public class dataObject
  {
    int a;
    String b;
  }
  </code></pre>
  
  <p>and in activity,</p>
  
  <p>I have made an array of dataObject, say dataObject x[5];  </p>
  
  <p>Now i want to pass these 5 dataObject to my javascript webView interface as JSON in a callback function.  </p>
  
  <p>I looked through the internet, seems like most tutorials talk about how to convert <code>fromJson()</code>.  There are not a lot about <code>toJson()</code>.  I found one that taught me that <code>dataObject.toJson()</code>, would work.  </p>
  
  <p>But how can I pass all 5 dataObjects?  </p>