March 2013
Beginner to intermediate
580 pages
16h 11m
English
Next, return to Crime.java and add a new JSON constant and a member variable to give Crime a field that will hold the name of a suspect. Also, modify the JSON methods to serialize the suspect into and out of JSON code and add new accessor methods.
Listing 21.2 Adding suspect field (Crime.java)
public class Crime {
...
private static final String JSON_PHOTO = "photo";
private static final String JSON_SUSPECT = "suspect";
...
private Photo mPhoto;
private String mSuspect;
public Crime(JSONObject json) throws JSONException {
mId = UUID.fromString(json.getString(JSON_ID));
...
if (json.has(JSON_PHOTO))
mPhoto = new Photo(json.getJSONObject(JSON_PHOTO));
if (json.has(JSON_SUSPECT))
mSuspect = json.getString(JSON_SUSPECT); ...Read now
Unlock full access