title: parse JSON with Mustache on Android
body: <p>I'm reading an array of JSON objects from an API, and hope to use Mustache to display the data in a nice HTML format.</p>
  
  <p>I downloaded the <a href="http://repo1.maven.org/maven2/com/samskivert/jmustache/1.3/jmustache-1.3.jar" rel="nofollow noreferrer">pre-built .jar file</a> from <a href="https://github.com/samskivert/jmustache" rel="nofollow noreferrer">https://github.com/samskivert/jmustache</a>, and ran the hello world with no problem:</p>
  
  <pre><code>String text = "One, two, {{three}}. Three sir!";
  Template tmpl = Mustache.compiler().compile(text);
  Map&lt;String, String&gt; data = new HashMap&lt;String, String&gt;();
  data.put("three", "five");
  Log.d("json",tmpl.execute(data));
  </code></pre>
  
  <p>How do I feed my JSONObject to Mustache?</p>
  
  <p>I tried this:</p>
  
  <pre><code>JSONObject eventJSON = events.getJSONObject(event_count);
  String text = "&lt;h1&gt;{{summary}}&lt;/h1&gt;";
  Template tmpl = Mustache.compiler().compile(text);
  Log.d("this breaks", tmpl.execute(eventJSON));
  </code></pre>
  
  <p>Logcat says <code>"No key, method or field with name 'summary' on line 1"</code></p>
  
  <p>I get the same error when sending a JSON string:</p>
  
  <pre><code>Log.d("this breaks", tmpl.execute(eventJSON.toString()));
  </code></pre>
  
  <p>eventJSON.toString() results in a <a href="http://pastebin.com/DmgMXu1f" rel="nofollow noreferrer">really long string</a> that starts</p>
  
  <pre><code>{"summary":"the LUSTER a.k.a. VJ WADAKENによるウィークデーモンスターパーティー。\r\n","invitations":[],"genres":[1,2],"open_date":"2011-11-17"...
  </code></pre>
  
  <p>Do I have to <a href="https://stackoverflow.com/questions/5565948/how-to-render-json-with-arbitrary-keys-using-mustache/5570022#5570022">convert the JSON to a hash</a>?</p>
  
  <p>Logcat full error:</p>
  
  <pre><code>11-17 12:04:19.080: E/AndroidRuntime(17227): FATAL EXCEPTION: AsyncTask #2
  11-17 12:04:19.080: E/AndroidRuntime(17227): java.lang.RuntimeException: An error occured while executing doInBackground()
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at android.os.AsyncTask$3.done(AsyncTask.java:266)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.lang.Thread.run(Thread.java:1020)
  11-17 12:04:19.080: E/AndroidRuntime(17227): Caused by: com.samskivert.mustache.MustacheException: No key, method or field with name 'summary' on line 1
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.samskivert.mustache.Mustache$VariableSegment.execute(Mustache.java:520)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.samskivert.mustache.Template.executeSegs(Template.java:70)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.samskivert.mustache.Template.execute(Template.java:58)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.samskivert.mustache.Template.execute(Template.java:48)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.example.android.events.AsyncJSONEventParser.parseEventJSON(AsyncJSONEventParser.java:88)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.example.android.events.AsyncJSONEventParser.doInBackground(AsyncJSONEventParser.java:40)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at com.example.android.events.AsyncJSONEventParser.doInBackground(AsyncJSONEventParser.java:1)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at android.os.AsyncTask$2.call(AsyncTask.java:252)
  11-17 12:04:19.080: E/AndroidRuntime(17227):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  </code></pre>