Back to project page PetBook.
The source code is released under:
MIT License
If you think the Android project PetBook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.edinubuntu.petlove.util.converter; /*from ww w . j a v a2s.co m*/ import android.util.Log; import com.edinubuntu.petlove.PetLove; import com.edinubuntu.petlove.object.Record; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; /** * Created by edward_chiang on 13/8/12. */ public class RecordsJsonConverter { private java.util.List<Record> records; public RecordsJsonConverter() { records = new ArrayList<Record>(); } public void convert(String jsonString) throws JSONException { JSONObject jsonObject = new JSONObject(jsonString); JSONArray recordsArray = jsonObject.getJSONObject("result").getJSONArray("records"); for (int index = 0; index < recordsArray.length(); index ++) { JSONObject recordObject = recordsArray.getJSONObject(index); Record record = new Record(); record.setRecordId(Integer.parseInt(recordObject.getString("_id"))); record.setAcceptNumber(recordObject.getString("AcceptNum")); record.setSterilization(recordObject.getString("IsSterilization")); record.setImageName(recordObject.getString("ImageName")); record.setName(recordObject.getString("Name")); record.setNote(recordObject.getString("Note")); record.setSex(recordObject.getString("Sex")); Log.d(PetLove.TAG, "Each record: "+record); records.add(record); } Log.d(PetLove.TAG, "Total count: "+records.size()); } public List<Record> getRecords() { return records; } }