如何处理sabre InstaFlight API JSON响应
我连接到saber InstaflightAPI,得到了JSON结果。输出字符串太长,我可以获取它们的值。但我的方法是占用大量内存。我想在VB.NET中使用一种占用更少内存的方法和一种动态方法 下面的代码工作正常,没有错误:如何处理sabre InstaFlight API JSON响应,json,vb.net,sabre,Json,Vb.net,Sabre,我连接到saber InstaflightAPI,得到了JSON结果。输出字符串太长,我可以获取它们的值。但我的方法是占用大量内存。我想在VB.NET中使用一种占用更少内存的方法和一种动态方法 下面的代码工作正常,没有错误: response2 = DirectCast(postReq.GetResponse(), HttpWebResponse) reader2 = New StreamReader(response2.GetResponseStream()) postReq.ContentT
response2 = DirectCast(postReq.GetResponse(), HttpWebResponse)
reader2 = New StreamReader(response2.GetResponseStream())
postReq.ContentType = "application/json; charset=utf-8"
Dim ser1 As JObject = JObject.Parse(reader2.ReadToEnd())
ElapseTime1 = ser1("PricedItineraries")(0)("AirItinerary")("OriginDestinationOptions")("OriginDestinationOption")(0)("ElapsedTime").Value(Of String)()
我可以得到这样的值,没有错误:
response2 = DirectCast(postReq.GetResponse(), HttpWebResponse)
reader2 = New StreamReader(response2.GetResponseStream())
postReq.ContentType = "application/json; charset=utf-8"
Dim ser1 As JObject = JObject.Parse(reader2.ReadToEnd())
ElapseTime1 = ser1("PricedItineraries")(0)("AirItinerary")("OriginDestinationOptions")("OriginDestinationOption")(0)("ElapsedTime").Value(Of String)()
然而,到了需要数百个变量的地步,这不是正确的方法
输出JSON的一个示例:
{“PricedItineraries”:[{“AirTrainer”:{“OriginDestinationOptions”:{“OriginDestinationOptions”:[{“FlightSegment”:{“出发机场”:{“LocationCode”:“JFK”},“ArrivalAirport”:{“LocationCode”:“LAS”},“MarketingAirline”:{“Code”:“AS”},“ArrivalTimeZone”:{“GMTOffset 7},“TPA\U Extensions”:{“eTicket,“StopQuantity”:0,“ElapsedTime”:344,“ResBookDesigCode”:“R”,“MarriageGrp”:“O”,“设备”:{“AirEquipment Type”:320},“出发日期时间”:“2017-07-07T09:30:00”,“抵达时间”:“2017-07-07T12:14:00”,“航班号”:1251,“实时性能”:{“百分比”:70},“运营航线”:{“公司短名”:“维珍美国”,“航班号”:251,“代码”:“VX”},“出发时区”:{“GMTOffset”:-4},{“出发机场”:{“位置代码”:“LAS”},“到达机场”:{“位置代码”:“LAX”},“市场航线”:{“代码”:“AS”},“到达时区”:{“GMTOffset”:-7},“TPAā扩展”:{“eTicket”:{“Ind”:true},“停止数量”:0,“延迟时间”:85,“重新设计代码”:“R”,“MarriageGrp”:“O”,“设备”:{“AirEquipment Type”:320},“出发日期时间”:“2017-07-07T14:45:00”,“抵达日期时间”:“2017-07-07T16:10:00”,“航班号”:1475,“实时性能”:{“百分比”:36},“运营航线”:{“公司短名”:“维珍美国”,“航班号”:475,“代码”:“VX”},“出发时区”:{“GMTOffset 7},“ElapsedTime”:580},{“航班段”:[{“出发机场”:{“地点代码”:“LAX”},“到达机场”:{“地点代码”:“LAS”},“市场航线”:{“代码”:“AS”},“到达时区”:{“GMTOffset”:-7},“TPA扩展”:{“eTicket”:{“Ind”:真的}},“停站时间”:0,“ElapsedCode 71”,“重新设计代码”:“R”,“MarriageGrp”:“O”“设备”:{“AirEquipment Type”:320},“出发日期时间”:“2017-07-08T17:00:00”,“抵达日期时间”:“2017-07-08T18:11:00”,“航班号”:1480,“实时性能”:{“百分比”:55},“运营航线”:{“公司短名”:“维珍美国”,“航班号”:480,“代码”:“VX”},“出发时区”:{“GMTOffset-7},{“出发机场”:{“地点代码”:“LAS”},“到达机场”:{“地点代码”:“JFK”},“市场航线”:{“代码”:“AS”},“到达机场地带”:{“GMTOffset”:-4},“TPA_扩展”:{“电子市场”:{“Ind”:true},“停止数量”:0
我认为您需要为这个结果创建一个模型。根据这个JSON,您必须创建一个类模型 如果您有此JSON:
{
"dailyDealId": "432",
"discountPercentage": "0",
"product": {
"productId": "10",
"brandId": "10",
"departmentId": "3",
"name": "Baby Girl Velour Tunic & Snowflake Legging Set",
"description": "The pretty set",
"url": "http://whatever.whatever.com/files/whatever.tif"
}
您需要此型号:
public class Product
{
public string productId { get; set; }
public string brandId { get; set; }
public string departmentId { get; set; }
public string name { get; set; }
public string description { get; set; }
public string url { get; set; }
}
public class Data
{
public string dailyDealId { get; set; }
public string discountPercentage { get; set; }
public Product product { get; set; }
}
您应该考虑将JSON浓缩为问题。请参阅如何创建。