// 正确返回数据
// {"error_code":"200","error":"\u8bf7\u6c42\u6210\u529f",
// "data":{"list":[{"id":"1","name":"\u5317\u4eac\u5927\u5b66","areaid":"1","logo":null,"info":null},
// {"id":"2","name":"\u5357\u660c\u5927\u5b66","areaid":null,"logo":null,"info":null}],"total":2}}
public LinkedList<ListCollegeModel> parseData(String jsonData) {
try {
JSONObject json = new JSONObject(jsonData);
JSONObject data = json.getJSONObject("data");
JSONArray array = data.getJSONArray("list");
LinkedList<ListCollegeModel> list = new LinkedList<ListCollegeModel>();
for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i);
String id = item.getString("id");
String name = item.getString("name");// 分类id
String areaid = item.getString("areaid");
String logo = item.getString("logo");
String info = item.getString("info");
ListCollegeModel model = new ListCollegeModel();
model.setId(id);
model.setName(name);
model.setAreaid(areaid);
model.setLogo(logo);
model.setInfo(info);
list.add(model);
ParseListCollegeData.lastId=new Integer(id);
}
return list;
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
/**
* 解析error_code不为200的数据
*
* @param jsonData
* @return
*/
public String parseErrorData(String jsonData) {
try {
JSONObject json = new JSONObject(jsonData);
String error = json.getString("error");
return error;
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
/**
*
* @param jsonData
* @return 返回服务器端的状态码
*/
public String getStatue(String jsonData) {
try {
JSONObject json = new JSONObject(jsonData);
String error_code = json.getString("error_code");
return error_code;
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public int getSum(String jsonData)
{
try {
JSONObject json = new JSONObject(jsonData);
JSONObject data = json.getJSONObject("data");
String sum=data.getString("total");
return new Integer(sum);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}