我的情况如下:在向服务器发送哈希后,我从服务器上的 php 脚本中得到一个 JSON 数组作为响应。JSON-Array 有两种可能的形式。如果哈希无效,第一个就像{"status":0}
. 第二种形式,当哈希有效时,其中会有约会 -> 就像{"appointmentName":"Meeting","date":"2013-03-15","startTime":"10:00:00","endTime":"12:10:00","status":2}
.
JSON-Array 可以填充不止一个约会。见下文:
{
"appointmentName": "Proposal",
"date": "2013-11-11",
"startTime": "09:00:00",
"endTime": "13:00:00",
"status": 2
}
{
"appointmentName": "Meeting",
"date": "2013-03-15",
"startTime": "10:00:00",
"endTime": "12:10:00",
"status": 2
}
我想在 android-app 的 ListView 中列出这些约会。
我处理 JSON 数组的方法:
public void handleActivationResult(String result) {
try {
JSONObject jsonObject = new JSONObject(new String(result));
String statusCode = jsonObject.getString("status");
TextView mainView = (TextView) findViewById(R.id.textView1);
if (statusCode.equals("2")) {
//fill listview with appointments
} else if (statusCode.equals(0)) {
//empty string sent to server
} else if (statusCode.equals(5)) {
//hash doesnt match
} else if (statusCode.equals(6)) {
//correct hash, but no upcoming appointments
} else {
//unknown error
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我的 ListView 还没有什么特别之处:
<ListView
android:id="@+id/appointmentsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
应该怎么做,handleActivationResult() 方法将用约会填充列表?