Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did something similar using the Gson library (http://code.google.com/p/google-gson/). I found it easier to use than Jackson.</p> <p>Here's an example of parsing a response for a contact that looks like it would translate well to your Cars example:</p> <pre><code>import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; ... public class TestContact implements Serializable { private static final long serialVersionUID = 1L; @SerializedName("Name") private String mName; @SerializedName("PhoneNumber") private String mPhoneNumber; @SerializedName("Address1") private String mAddress1; @SerializedName("Address2") private String mAddress2; @SerializedName("City") private String mCity; @SerializedName("State") private String mState; @SerializedName("Zip") private String mZip; @SerializedName("Website") private String mWebsite; @SerializedName("Email") private String mEmail; public static TestContact create(JSONObject response) throws JSONException { Gson gson = new Gson(); TestContact contact = gson.fromJson(response.toString(), TestContact.class); return contact; } public static ArrayList&lt;TestContact&gt; createList(JSONObject response) throws JSONException { ArrayList&lt;TestContact&gt; contacts = new ArrayList&lt;TestContact&gt;(); JSONArray contactResponses = response.getJSONArray("Contacts"); for (int i = 0; i &lt; contactResponses.length(); i++) { JSONObject contactResponse = contactResponses.getJSONObject(i); contacts.add(create(contactResponse)); } return contacts; } ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload