使用此网址:https://qpx-express-demo.itasoftware.com/我正在请求在未来某个日期从BOM到纽约获取航班可用性。 我收到的JSON响应:
格式化响应: 解决方案#1促销价:INR31803 切片0 KU 302 BOM 2016-01-29T05:50 + 05:30 KWI 2016-01-29T07:50 + 03:00 KU 117 KWI 2016-01-29T09:55 + 03:00 JFK 2016-01-29T16:20-05:00
未格式化的回复:
{
"kind": "qpxexpress#tripOption",
"saleTotal": "INR31803",
"id": "5WAPnfYj8mARdie1jBKphP002",
"slice": [
{
"kind": "qpxexpress#sliceInfo",
"duration": 1260,
"segment": [
{
"kind": "qpxexpress#segmentInfo",
"duration": 270,
"flight": {
"carrier": "KU",
"number": "302"
},
"id": "G9ieitLhcbGEpU6u",
"cabin": "COACH",
"bookingCode": "H",
"bookingCodeCount": 9,
"marriedSegmentGroup": "0",
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": "LRlNO3Gw0UX8y69J",
"aircraft": "777",
"arrivalTime": "2016-01-29T07:50+03:00",
"departureTime": "2016-01-29T05:50+05:30",
"origin": "BOM",
"destination": "KWI",
"originTerminal": "2",
"destinationTerminal": "M",
"duration": 270,
"mileage": 1713,
"meal": "Breakfast",
"secure": true
}
],
"connectionDuration": 125
},
{
"kind": "qpxexpress#segmentInfo",
"duration": 865,
"flight": {
"carrier": "KU",
"number": "117"
},
"id": "GBan4WxY2pcKVHbu",
"cabin": "COACH",
"bookingCode": "H",
"bookingCodeCount": 9,
"marriedSegmentGroup": "1",
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": "L9pmI3XsVZSBhZah",
"aircraft": "777",
"arrivalTime": "2016-01-29T16:20-05:00",
"departureTime": "2016-01-29T09:55+03:00",
"origin": "KWI",
"destination": "JFK",
"originTerminal": "M",
"destinationTerminal": "4",
"duration": 865,
"mileage": 6336,
"meal": "Meal",
"secure": true
}
]
}
]
}
],
"pricing": [
{
"kind": "qpxexpress#pricingInfo",
"fare": [
{
"kind": "qpxexpress#fareInfo",
"id": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"carrier": "KU",
"origin": "BOM",
"destination": "NYC",
"basisCode": "HLOWIN1"
}
],
"segmentPricing": [
{
"kind": "qpxexpress#segmentPricing",
"fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"segmentId": "G9ieitLhcbGEpU6u"
},
{
"kind": "qpxexpress#segmentPricing",
"fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"segmentId": "GBan4WxY2pcKVHbu"
}
],
"baseFareTotal": "INR26460",
"saleFareTotal": "INR26460",
"saleTaxTotal": "INR5343",
"saleTotal": "INR31803",
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": 1
},
"tax": [
{
"kind": "qpxexpress#taxInfo",
"id": "JN_004",
"chargeType": "GOVERNMENT",
"code": "JN",
"country": "IN",
"salePrice": "INR1482"
},
{
"kind": "qpxexpress#taxInfo",
"id": "F2_001",
"chargeType": "GOVERNMENT",
"code": "F2",
"country": "IN",
"salePrice": "INR53"
},
{
"kind": "qpxexpress#taxInfo",
"id": "IN",
"chargeType": "GOVERNMENT",
"code": "IN",
"country": "IN",
"salePrice": "INR627"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YM_001",
"chargeType": "GOVERNMENT",
"code": "YM",
"country": "IN",
"salePrice": "INR687"
},
{
"kind": "qpxexpress#taxInfo",
"id": "WO_001",
"chargeType": "GOVERNMENT",
"code": "WO",
"country": "IN",
"salePrice": "INR149"
},
{
"kind": "qpxexpress#taxInfo",
"id": "US_002",
"chargeType": "GOVERNMENT",
"code": "US",
"country": "US",
"salePrice": "INR1190"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YX_001",
"chargeType": "GOVERNMENT",
"code": "YX",
"country": "KW",
"salePrice": "INR54"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YC",
"chargeType": "GOVERNMENT",
"code": "YC",
"country": "US",
"salePrice": "INR368"
},
{
"kind": "qpxexpress#taxInfo",
"id": "XY",
"chargeType": "GOVERNMENT",
"code": "XY",
"country": "US",
"salePrice": "INR468"
},
{
"kind": "qpxexpress#taxInfo",
"id": "XA",
"chargeType": "GOVERNMENT",
"code": "XA",
"country": "US",
"salePrice": "INR265"
}
],
"fareCalculation": "BOM KU X/KWI KU NYC 397.64HLOWIN1 NUC 397.64 END ROE 66.541160 FARE INR 26460 XT 53F2 627IN 1482JN 149WO 687YM 54YX 368YC 468XY 265XA 1190US",
"latestTicketingTime": "2016-01-28T19:19-05:00",
"ptc": "ADT",
"refundable": true
}
从响应中推断出有两个片段,一个是KU 302,另一个是KU 117.我如何从响应获得每段(每个航班)信息?
答案 0 :(得分:1)
我在C#中使用API,如果你安装了Json.NET NuGet包,你就可以获得响应并反序列化它:
JsonConvert.DeserializeObject<Response>(jsonString);
要构建Response对象,您可以使用在线Json到C#类构建器(Google和它立即找到它),或者您可以使用动态对象。
一旦你有反序列化的响应,你可以使用LINQ来过滤信息:
from r in response where <filters> select r.segment // Or specific data.
所有这些假设你想要使用C#。