将JSON数组提取到ListView Android

时间:2016-08-04 05:26:00

标签: android arrays json

我有来自服务器的响应:

enter image description here

如何获取该响应:

ListOrderItem orderItem = new ListOrderItem();

orderItem.setId_order(order_id);

orderItem.setUser_phone(order_user_phone);

orderItem.setUser_name(order_user_name);

orderItem.setVehicle_type(order_vehicle_type);

orderItem.setVehicle_brand(order_vehicle_merk);

orderItem.setVehicle_year(order_vehicle_year);

orderItem.setNote(order_note);

orderItem.setLongitude(order_longitude);

orderItem.setLatitude(order_latitude);

orderItem.setLocation(order_location);

arrayOrder.add(orderItem);

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

JSONObject response = new JSONObject(new String(yourResponseString));
int flag = response.getInt("code");
if ( flag == 200 ) {

  JSONArray message = response.getJSONArray("message");
   for (int i = 0; i < message.length(); i++) {
       ListOrderItem orderItem = new ListOrderItem();
        JSONObject eachMessage = message.getJSONObject(i);
        orderItem.setId_order(eachMessage.getString("order_id"));
        orderItem.setUser_phone(eachMessage.getString("order_user_phone"));
        orderItem.setUser_name(eachMessage.getString("order_user_name"));
        orderItem.setVehicle_type(eachMessage.getString("order_vehicle_type"));
        orderItem.setVehicle_brand(eachMessage.getString("order_vehicle_merk"));
        orderItem.setVehicle_year(eachMessage.getString("order_vehicle_year"));
        orderItem.setNote(eachMessage.getString("order_note"));
        orderItem.setLongitude(eachMessage.getString("order_longitude"));
        orderItem.setLatitude(eachMessage.getString("order_latitude"));
        orderItem.setLocation(eachMessage.getString("order_location"));
        arrayOrder.add(orderItem);

   }

}