dongwolu5275 2018-09-05 05:29
浏览 41

如何在Rest API中解决此数组错误

I am creating a ticket reservation system. So , in this system I used API to request and get(response) data. But , when I got the response from API , it contains arrays of arrays.

{
  "OTA_AirLowFareSearchRS": {
    "PricedItinCount": 25,
    "BrandedOneWayItinCount": 0,
    "SimpleOneWayItinCount": 0,
    "DepartedItinCount": 0,
    "SoldOutItinCount": 0,
    "AvailableItinCount": 0,
    "Version": "4.2.0",
    "Success": {},
    "Warnings": {
      "Warning": [
        {
          "Type": "WORKERTHREAD",
          "ShortText": "2878556866627349184",
          "Code": "TRANSACTIONID",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "SERVER",
          "ShortText": "27041",
          "Code": "TTFHLC703",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "DRE",
          "ShortText": "13291",
          "Code": "RULEID",
          "MessageClass": "I",
          "content": ""
        },
        {
          "Type": "DEFAULT",
          "ShortText": "25238",
          "Code": "RULEID",
          "MessageClass": "I",
          "content": ""
        }
      ]
    },
    "PricedItineraries": {
      "PricedItinerary": [
        {
          "SequenceNumber": 1,
          "AirItinerary": {
            "DirectionInd": "Return",
            "OriginDestinationOptions": {
              "OriginDestinationOption": [
                {
                  "ElapsedTime": 1030,
                  "FlightSegment": [
                    {
                      "DepartureDateTime": "2018-11-10T07:10:00",
                      "ArrivalDateTime": "2018-11-10T08:38:00",
                      "StopQuantity": 0,
                      "FlightNumber": "2912",
                      "ResBookDesigCode": "V",
                      "ElapsedTime": 208,
                      "DepartureAirport": {
                        "LocationCode": "DFW",
                        "TerminalID": "E",
                        "content": ""
                      },
                      "ArrivalAirport": {
                        "LocationCode": "LAX",
                        "TerminalID": "2",
                        "content": ""
                      },
                      "OperatingAirline": {
                        "Code": "DL",
                        "FlightNumber": "2912",
                        "content": ""
                      },
                      "Equipment": [
                        {
                          "AirEquipType": "319",
                          "content": ""
                        }
                      ],
                      "MarketingAirline": {
                        "Code": "DL",
                        "content": ""
                      },
                      "MarriageGrp": "O",
                      "DepartureTimeZone": {
                        "GMTOffset": -6
                      },
                      "ArrivalTimeZone": {
                        "GMTOffset": -8
                      },
                      "OnTimePerformance": {
                        "Level": "7"
                      },
                      "TPA_Extensions": {
                        "eTicket": {
                          "Ind": true
                        },
                        "Mileage": {
                          "Amount": 1235
                        }
                      }
                    }
                    ]
                    }

Now I want to read and display these values in the view page. I mean I want to get and display PricedItinCount , DepartureDateTime and ArrivalAirport->LocationCode. Then I tried below steps with Jquery and Ajax. I got all the details with

Console.log(data);

But, couldn't get any thing into the view page. How can I get values to the view page ??

View page.

<form class="form-horizontal" method="POST" action="#" enctype="multipart/form-data" id="signupForm">

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Origin City : <input type="text" class="form-control" name="origin" value="CMB" id="origin"> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Destination City : <input type="text" class="form-control" name="destination" value="DUB"
                                              id="destination"> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->

                    <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                        Adults : <select name="adults" class="form-control" id="adults">
                            <option value="1">1</option>
                        </select> <br>
                    </div>

                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Departure Date : <input class="form-control" name="departureDate" id="departureDate">
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Return Date : <input class="form-control" name="returnDate" id="returnDate">
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Travel Class : <select name="travelClass" class="form-control" id="travelClass">
                            <option value="ECONOMY">ECONOMY</option>
                            <option value="BUSINESS">BUSINESS</option>
                    </select> <br>
                </div>

                <div class="col-md-4 col-sm-12 hero-feature"> <!-- Start Of The Col Class -->
                    Access Token : <input type="text" class="form-control" name="bat" value="" id="bat">
                </div>

                <a href="#" id="ghsubmitbtn" class="btn btn-success">Search Flight Data</a>

                <p id="errorModal"></p> <br>

                <div id="ghapidata" class="clearfix"></div>

            </form>

            <h3>Tasks of the Developers</h3> <br>

            <div class="table-responsive">
                <table class="table table-striped table-bordered text-left" id="tblData">
                    <thead>
                    <tr class="info">
                        <td>PricedItinCount</td>
                        <td>Id</td>
                    </tr>

                    <tbody id="tblBody"></tbody>
                    </thead>
                </table>
            </div>

            <script type="text/javascript">
                $(document).ready(function () {

                    $('#ghsubmitbtn').on('click', function(e) {
                        var Target = 'Production';
                        var bat = 'T1RLAQJBqX+k4EiXWQziU3GvPPsN69ozuhBwOBhA97cFiyxKiyylxmA1AADAM6s/5sV+ZLOBPsYTHiPtad9ByBlsN91C4XxIhcT6kLibIww/Ezpv3CvJCwcp7xJZhU0oQLpu+8DVQ3lcsgnUGkAeu4SvF7h4BJs5IMpkVgpuTOEX9jeGT2TljavgPtrqVG62xcX2ZPYEOKO20IPQqZE9isl9EQH1bgRVCba0FzQ7m6zbfPGpwf20KCWMCfO69IYTbx5krbLf3aIyp8Db+5GSXKOdqIp6s9aDP0RIrkmDhEYO3H8tYTIqj6rQPrjf';

                         var JSONObj = {
                         "OTA_AirLowFareSearchRQ": {
                             "Target": Target,
                               "POS": {
                                    "Source": [{
                                        "PseudoCityCode":"F9CE",
                                        "RequestorID": {
                                            "Type": "1",
                                          "ID": "1",
                                            "CompanyName": {

                                          }
                                     }
                                 }]
                                },
                                "OriginDestinationInformation": [{
                                  "RPH": "1",
                                   "DepartureDateTime": "2018-11-10T11:00:00",
                                   "OriginLocation": {
                                     "LocationCode": "DFW"
                                 },
                                    "DestinationLocation": {
                                        "LocationCode": "CDG"
                                 },
                                    "TPA_Extensions": {
                                     "SegmentType": {
                                            "Code": "O"
                                       }
                                 }
                             },
                                {
                                 "RPH": "2",
                                   "DepartureDateTime": "2018-11-11T11:00:00",
                                   "OriginLocation": {
                                     "LocationCode": "CDG"
                                 },
                                    "DestinationLocation": {
                                        "LocationCode": "DFW"
                                 },
                                    "TPA_Extensions": {
                                     "SegmentType": {
                                            "Code": "O"
                                       }
                                 }
                             }],
                               "TravelPreferences": {
                                  "ValidInterlineTicket": true,
                                   "CabinPref": [{
                                     "Cabin": "Y",
                                     "PreferLevel": "Preferred"
                                    }],
                                   "TPA_Extensions": {
                                     "TripType": {
                                           "Value": "Return"
                                     },
                                        "LongConnectTime": {
                                            "Min": 780,
                                         "Max": 1200,
                                            "Enable": true
                                      },
                                        "ExcludeCallDirectCarriers": {
                                          "Enabled": true
                                     }
                                 }
                             },
                                "TravelerInfoSummary": {
                                    "SeatsRequested": [1],
                                  "AirTravelerAvail": [{
                                      "PassengerTypeQuantity": [{
                                         "Code": "ADT",
                                            "Quantity": 1
                                       }]
                                    }]
                                },
                                "TPA_Extensions": {
                                 "IntelliSellTransaction": {
                                     "RequestType": {
                                            "Name": "50ITINS"
                                     }
                                 }
                             }
                         }
                        };

                        var data = JSON.stringify(JSONObj);

                        $.ajax({
                            url: 'https://api-crt.cert.havail.sabre.com/v4.2.0/shop/flights?mode=live&limit=50&offset=1',
                            method: 'POST',
                            contentType:"application/json; charset=utf-8",
                            data: data,
                            headers: {"Authorization": 'Bearer ' + bat},

                            success: function (data) {

                                console.log(data);

                                $.each(data, function (index, value) {

                                    var BookBtn = '<input type="submit" value="Book" name="book" class="btn btn-primary">';

                                    for (var v = 0; v <= 999; v++) {
                                    var row = $('<tr><td>' + value[0].PricedItinCount + '</td><td>'
                                        + value[v].Version + '</td><td>'
                                        + value[v].Warnings[0].Warning[0].Type + '</td><td>'
                                        + BookBtn + '</td></tr>');
                                    $('#tblData').append(row);}
                                });


                            },

                        });
                    });
                });
            </script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型