Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从复杂的JSON响应检索Android中嵌套的JSON数组/对象_Android_Json_Arraylist_Android Listview_Nested Loops - Fatal编程技术网

从复杂的JSON响应检索Android中嵌套的JSON数组/对象

从复杂的JSON响应检索Android中嵌套的JSON数组/对象,android,json,arraylist,android-listview,nested-loops,Android,Json,Arraylist,Android Listview,Nested Loops,我必须将下面嵌套的JSON数组的数据解析到我的应用程序中。我不知道如何从中获取值。因为它太复杂,url为“” JSON响应由嵌套数组和对象组成。我正在使用Volley库函数解析JSON。我希望从响应中获取值,以便生成listview。但是我没有得到结果。有人帮我解决这个问题吗。我不熟悉嵌套JSON数组 {"tag":"Flight SearchResults","success":"1","xml_filename":"dom_20150527135409.xml", "data": [{"

我必须将下面嵌套的JSON数组的数据解析到我的应用程序中。我不知道如何从中获取值。因为它太复杂,url为“”

JSON响应由嵌套数组和对象组成。我正在使用Volley库函数解析JSON。我希望从响应中获取值,以便生成listview。但是我没有得到结果。有人帮我解决这个问题吗。我不熟悉嵌套JSON数组

{"tag":"Flight SearchResults","success":"1","xml_filename":"dom_20150527135409.xml",

"data":

[{"depart_from_location":"Bangalore","depart_from_location_code":"BLR","depart_to_location":"Calicut","depart_to_location_code":"CCJ","depart_date":"Fri, 05 June 2015","return_from_location":"Calicut","return_from_location_code":"CCJ","return_to_location":"Bangalore","return_to_location_code":"BLR","return_date":"Sat, 06 June 2015",

"departure_details":[{"flight_id":"arzoo11","flights_count":"2",

"flight_details":

[{"image_filename":"http:\/\/live.arzoo.com\/FlightWS\/image\/AirIndia.gif","air

line_name":"Air India","flight_number":"608","departure_location_code":"BLR","arrival_location_code":"BOM","departure_location":"Bangalore ","departure_time":"21:20","arrival_location":"Mumbai","arrival_time":"23:00","fare_rules":"This fare is Non Refundable Booking Class : T|Cancellation Penalty: All bookings done are subject to cancellation penalty levied by the airlines.<br>In addition to the airlines cancellation penalty, we charge a service fee of Rs. 50 per passenger for all cancellations.|Date Change Penalty: In addition to the airlines date change penalty, we charge a service fee of Rs. 50 per passenger.|"},{"image_filename":"http:\/\/live.arzoo.com\/FlightWS\/image\/AirIndia.gif","airline_name":"Air India","flight_number":"657","departure_location_code":"BOM","arrival_location_code":"CCJ","departure_location":"Mumbai","departure_time":"10:00","arrival_location":"Calicut","arrival_time":"13:05","fare_rules":"This fare is Non Refundable Booking Class : T|Cancellation Penalty: All bookings done are subject to cancellation penalty levied by the airlines.<br>In addition to the airlines cancellation penalty, we charge a service fee of Rs. 50 per passenger for all cancellations.|Date Change Penalty: In addition to the airlines date change penalty, we charge a service fee of Rs. 50 per passenger.|"}],

"fare_details":

{"base_fare":"7301","airport_tax":"5365","service_tax":"46","transaction_charge":"0","total":12962,"total_amount":"12962.00"}},
{“tag”:“航班搜索结果”,“成功”:“1”,“xml_文件名”:“dom_20150527135409.xml”,
“数据”:
[{“离开地点”:“班加罗尔”,“离开地点代码”:“BLR”,“离开地点代码”:“Calicut”,“离开地点代码”:“CCJ”,“离开日期”:“2015年6月5日星期五”,“从地点返回”:“Calicut”,“从地点返回代码”:“CCJ”,“返回地点”:“班加罗尔”,“返回地点代码”:“BLR”,“返回日期”:“2015年6月6日星期六”,
“起飞详情”:[{“航班id”:“arzoo11”,“航班计数”:“2”,
“航班详情”:
[{“image\u filename”:“http:\/\/live.arzoo.com\/FlightWS\/image\/airnia.gif”,“air”
行名“:“印度航空”,“航班号“:“608”,“出发地点代码“:“BLR”,“到达地点代码“:“BOM”,“出发地点“:“班加罗尔”,“出发时间“:“21:20”,“到达地点“:“孟买”,“到达时间“:“23:00”,“票价规则”:"此票价为不可退还的订票等级:T |取消罚款:所有订票都将受到航空公司的取消罚款。
除航空公司取消罚款外,我们对所有取消的订票收取每位乘客50卢比的服务费。|日期更改罚款:除航空公司日期更改罚款外,我们还收取每位乘客的服务费为50卢比。{“image\u filename”:“http:\/\/live.arzoo.com\/FlightWS\/image\/AirIndia.gif”,“航空公司名称”:“印度航空”,“航班号”:“657”,“出发地点代码”:“BOM”,“到达地点代码”:“CCJ”,“出发地点”:“孟买”,“出发时间”:“10:00”,“到达地点”:“Calicut”,“到达时间”:“13:05”,“票价规则”:此票价为不可退还的订票等级:T |取消罚款:所有订票都将受到航空公司的取消罚款。
除航空公司取消罚款外,我们对所有取消的订票收取每位乘客50卢比的服务费。|日期更改罚款:除航空公司日期更改罚款外,我们还收取每位乘客50卢比的服务费, “票价详情”: {“基本票价”:“7301”,“机场税”:“5365”,“服务税”:“46”,“交易费”:“0”,“总额”:12962,“总额”:“12962.00”},
下面给出了我迄今为止尝试过的代码,我正在使用截取进行解析

private void json_parser(JSONArray jarray){
  try  {

        flightList=new ArrayList<Flight>();
      for (int i = 0; i < jarray.length(); i++) {

            JSONObject object = jarray.getJSONObject(i);

          JSONArray departure_details=object.getJSONArray("departure_details");
          if(departure_details!=null)
          {
              for(int j=0;j<departure_details.length();j++)
              {
                  JSONObject object2=departure_details.getJSONObject(j);
                  String flight_count=object2.getString("flight_count");


            JSONArray flight_details=object2.getJSONArray("flight_details");
                  if(flight_details!=null)
                  {
                      for(int k=0;k<flight_details.length();k++)
                      {
    JSONObject object3=flight_details.getJSONObject(k);
                          String flight_name=object3.getString("airline_name");
                          String dep_location_code=object3.getString("departure_location_code");
                          String arr_location_code=object3.getString("arrival_location_code");
    String dep_time=object3.getString("departure_time");
                          String arr_time=object3.getString("arrival_time");

          JSONObject fare_details=object.getJSONObject("fare_details");
                          Toast.makeText(getApplicationContext(),object.getString("depart_from_location_code"), Toast.LENGTH_LONG).show();
           flightList.add(new Flight( object.getString("depart_from_location_code"),object.getString("depart_to_location_code"),flight_count,flight_name,object.getString("depart_date"),object.getString("depart_date"),dep_time,arr_time,dep_location_code,arr_location_code,dep_location_code,arr_location_code));

        }}}}}
        list.setAdapter( new FlightListAdapter(ctx, R.layout.flight_list, flightList) ); 
private void json_解析器(JSONArray-jarray){
试一试{
flightList=newarraylist();
for(int i=0;iprivate-void-json_解析器(JSONArray-jarray){
试一试{
ArrayList flightList=新建ArrayList();
for(int i=0;iprivate void json_parser(JSONArray jarray) {
    try {

        ArrayList flightList = new ArrayList<Flight>();
        for (int i = 0; i < jarray.length(); i++) {

            JSONObject object = jarray.getJSONObject(i);

            JSONArray departure_details = object
                    .getJSONArray("departure_details");
            if (departure_details != null) {
                for (int j = 0; j < departure_details.length(); j++) {
                    JSONObject object2 = departure_details.getJSONObject(j);

                    String flight_count = object2
                            .getString("flights_count");

                    JSONObject fare_details = object2
                            .getJSONObject("fare_details");

                    String base_fare, airport_tax, service_tax, transaction_charge, total, total_amount;

                    Log.i("fare_details",
                            "fare_details:" + fare_details.toString());
                    for (int k = 0; k < fare_details.length(); k++) {
                        base_fare = fare_details.getString("base_fare");
                        airport_tax = fare_details.getString("airport_tax");
                        service_tax = fare_details.getString("service_tax");
                        transaction_charge = fare_details
                                .getString("transaction_charge");
                        total = fare_details.getString("total");
                        total_amount = fare_details
                                .getString("total_amount");

                    }

                    JSONArray flight_details = object2
                            .getJSONArray("flight_details");
                    if (flight_details != null) {
                        Log.i("flight_details", "flight_details:"
                                + flight_details.toString());

                        for (int k = 0; k < flight_details.length(); k++) {
                            JSONObject object3 = flight_details
                                    .getJSONObject(k);
                            String flight_name = object3
                                    .getString("airline_name");
                            String dep_location_code = object3
                                    .getString("departure_location_code");
                            String arr_location_code = object3
                                    .getString("arrival_location_code");
                            String dep_time = object3
                                    .getString("departure_time");
                            String arr_time = object3
                                    .getString("arrival_time");

                            flightList
                                    .add(new Flight(
                                            object.getString("depart_from_location_code"),
                                            object.getString("depart_to_location_code"),
                                            flight_count,
                                            flight_name,
                                            object.getString("depart_date"),
                                            object.getString("depart_date"),
                                            dep_time, arr_time,
                                            dep_location_code,
                                            arr_location_code,
                                            dep_location_code,
                                            arr_location_code));
                        }

                    }

                }
            }
        }
        Log.i("array list length", "" + flightList.size());

    } catch (Exception e) {
        e.printStackTrace();
    }

}