- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我真的被这个问题困扰了 2 天,我怎样才能从深度嵌套的 json 对象中获取数据。
我在网上找到了一个json工具http://www.jsoneditoronline.org/ http://jsonformat.com/当您将 json 粘贴到其中时,它会显示所有对象数组等,因此我可以深入挖掘数据并获取我想要的信息。
当我调试代码并在以下位置设置断点时:foreach(rates.ToArray() 中的 JToken 数据)
,取决于我尝试的内容取决于我得到的错误,最后一个错误是。
Error converting value "@rateChange" to type 'Web.UI.Controllers.HomeController+RateInfo'.
Could not cast or convert from System.String to Web.UI.Controllers.HomeController+RateInfo.
非常感谢任何帮助。
我的类(class)
public class RateInfo
{
public string RateChange { get; set; }
public string Promo { get; set; }
public string PriceBreakdown { get; set; }
public bool NonRefundable { get; set; }
public string RateType { get; set; }
public int CurrentAllotment { get; set; }
public int? PromoId { get; set; }
public string PromoDescription { get; set; }
public string PromoType { get; set; }
}
代码
IList<JToken> rates = root["HotelListResponse"]["HotelList"]["HotelSummary"][0]["RoomRateDetailsList"]["RoomRateDetails"]["RateInfos"]["RateInfo"].Children().ToList();
IList<RateInfo> info = new List<RateInfo>();
foreach (JToken data in rates.ToArray())
{
RateInfo rateInfo = JsonConvert.DeserializeObject<RateInfo>(data.ToString());
info.Add(rateInfo);
}
JSON
{ "HotelListResponse" : { "HotelList" : { "@activePropertyCount" : "168",
"@size" : "2",
"HotelSummary" : [ { "@order" : "0",
"@ubsScore" : "360017",
"RoomRateDetailsList" : { "RoomRateDetails" : { "RateInfos" : { "@size" : "1",
"RateInfo" : { "@priceBreakdown" : "true",
"@promo" : "true",
"@rateChange" : "true",
"ChargeableRateInfo" : { "@averageBaseRate" : "68.62333",
"@averageRate" : "68.62333",
"@commissionableUsdTotal" : "205.87",
"@currencyCode" : "USD",
"@grossProfitOffline" : "14.06",
"@grossProfitOnline" : "27.44",
"@maxNightlyRate" : "77.87",
"@nightlyRateTotal" : "205.87",
"@total" : "205.87",
"NightlyRatesPerRoom" : { "@size" : "3",
"NightlyRate" : [ { "@baseRate" : "77.87",
"@promo" : "false",
"@rate" : "77.87"
},
{ "@baseRate" : "64.0",
"@promo" : "false",
"@rate" : "64.0"
},
{ "@baseRate" : "64.0",
"@promo" : "false",
"@rate" : "64.0"
}
]
}
},
"RoomGroup" : { "Room" : { "numberOfAdults" : 2,
"numberOfChildren" : 0,
"rateKey" : "f82ab843-49ee-481a-b53a-71647592b183"
} },
"currentAllotment" : 0,
"nonRefundable" : true,
"promoDescription" : "Advance Purchase Special - non-refundable",
"promoId" : 200827770,
"promoType" : "Standard",
"rateType" : "MerchantStandard"
}
},
"ValueAdds" : { "@size" : "1",
"ValueAdd" : { "@id" : "2048",
"description" : "Free Wireless Internet"
}
},
"expediaPropertyId" : 3084588,
"maxRoomOccupancy" : 3,
"minGuestAge" : 0,
"propertyAvailable" : true,
"propertyRestricted" : false,
"quotedRoomOccupancy" : 2,
"rateCode" : 200371945,
"roomDescription" : "Standard Room with King size bed",
"roomTypeCode" : 477014
} },
"address1" : "Stone Cellar Road",
"address2" : "High Usworth Newcastle",
"airportCode" : " ",
"amenityMask" : 18063491,
"city" : "Washington",
"confidenceRating" : 90,
"countryCode" : "GB",
"deepLink" : "http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=340461&mode=2&numberOfRooms=1&room-0-adult-total=2&room-0-child-total=0&arrivalMonth=11&arrivalDay=12&departureMonth=11&departureDay=15&showInfo=true&locale=en_US¤cyCode=USD",
"highRate" : 77.870000000000005,
"hotelId" : 340461,
"hotelInDestination" : true,
"hotelRating" : 3,
"latitude" : 54.922739999999997,
"locationDescription" : "Near Washington Old Hall",
"longitude" : -1.5342899999999999,
"lowRate" : 64,
"name" : "Mercure Newcastle George Washington Hotel Golf and Spa",
"postalCode" : "NE37 1PH",
"propertyCategory" : 1,
"proximityDistance" : 1.4710813,
"proximityUnit" : "MI",
"rateCurrencyCode" : "USD",
"shortDescription" : "<p><b>Location. </b> <br />Mercure Newcastle George Washington Hotel Golf and Spa is a business-friendly hotel located in Washington, close to Washington Old Hall, Angel of the North, and WWT",
"supplierType" : "E",
"thumbNailUrl" : "/hotels/4000000/3090000/3084600/3084588/3084588_84_t.jpg",
"tripAdvisorRating" : 3.5,
"tripAdvisorRatingUrl" : "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/3.5-12345-4.gif",
"tripAdvisorReviewCount" : 215
},
{ "@order" : "1",
"@ubsScore" : "258461",
"RoomRateDetailsList" : { "RoomRateDetails" : { "RateInfos" : { "@size" : "1",
"RateInfo" : { "@priceBreakdown" : "true",
"@promo" : "false",
"@rateChange" : "true",
"ChargeableRateInfo" : { "@averageBaseRate" : "54.83667",
"@averageRate" : "54.83667",
"@commissionableUsdTotal" : "164.51001",
"@currencyCode" : "USD",
"@grossProfitOffline" : "11.69",
"@grossProfitOnline" : "22.38",
"@maxNightlyRate" : "63.47",
"@nightlyRateTotal" : "164.51001",
"@total" : "164.51",
"NightlyRatesPerRoom" : { "@size" : "3",
"NightlyRate" : [ { "@baseRate" : "50.52",
"@promo" : "false",
"@rate" : "50.52"
},
{ "@baseRate" : "50.52",
"@promo" : "false",
"@rate" : "50.52"
},
{ "@baseRate" : "63.47",
"@promo" : "false",
"@rate" : "63.47"
}
]
}
},
"RoomGroup" : { "Room" : { "numberOfAdults" : 2,
"numberOfChildren" : 0,
"rateKey" : "f82ab843-49ee-481a-b53a-71647592b183"
} },
"currentAllotment" : 0,
"nonRefundable" : true,
"rateType" : "MerchantStandard"
}
},
"expediaPropertyId" : 901118,
"maxRoomOccupancy" : 2,
"minGuestAge" : 0,
"propertyAvailable" : true,
"propertyRestricted" : false,
"quotedRoomOccupancy" : 2,
"rateCode" : 200369466,
"roomDescription" : "Standard room with double bed - Book early & Save",
"roomTypeCode" : 162976
} },
"address1" : "Emerson Road",
"address2" : "District 5",
"airportCode" : "NCL",
"amenityMask" : 1507328,
"city" : "Washington",
"confidenceRating" : 85,
"countryCode" : "GB",
"deepLink" : "http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=207631&mode=2&numberOfRooms=1&room-0-adult-total=2&room-0-child-total=0&arrivalMonth=11&arrivalDay=12&departureMonth=11&departureDay=15&showInfo=true&locale=en_US¤cyCode=USD",
"highRate" : 63.469999999999999,
"hotelId" : 207631,
"hotelInDestination" : true,
"hotelRating" : 2,
"latitude" : 54.895090000000003,
"locationDescription" : "Near Washington Old Hall",
"longitude" : -1.55661,
"lowRate" : 50.520000000000003,
"name" : "Campanile Washington Newcastle Upon Tyne",
"postalCode" : "NE37 1LB",
"propertyCategory" : 1,
"proximityDistance" : 1.2526573000000001,
"proximityUnit" : "MI",
"rateCurrencyCode" : "USD",
"shortDescription" : "<p><b>Location. </b> <br />Campanile Washington Newcastle Upon Tyne is located in Washington, close to Washington Old Hall, Angel of the North, and WWT Washington Wetland Centre. Additional area",
"supplierType" : "E",
"thumbNailUrl" : "/hotels/1000000/910000/901200/901118/901118_20_t.jpg",
"tripAdvisorRating" : 3.5,
"tripAdvisorRatingUrl" : "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/3.5-12345-4.gif",
"tripAdvisorReviewCount" : 55
}
]
},
"cacheKey" : "4ef59f3e:13e1c495694:-6e28",
"cacheLocation" : "10.186.168.74:7301",
"cachedSupplierResponse" : { "@cachedTime" : "0",
"@candidatePreptime" : "100",
"@matchedCurrency" : "true",
"@matchedLocale" : "true",
"@otherOverheadTime" : "3",
"@supplierCacheTolerance" : "MED",
"@supplierRequestNum" : "118",
"@supplierResponseNum" : "2",
"@supplierResponseTime" : "468",
"@tpidUsed" : "5200"
},
"customerSessionId" : "0ABAA84A-59F3-E913-E1C2-495694906E33",
"moreResultsAvailable" : true,
"numberOfRoomsRequested" : 1
} }
=============================这段代码可以从摘要数组中获取数据========= ===
public class Hotelsummary
{
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string PostalCode { get; set; }
public string CountryCode { get; set; }
public string ThumbNailUrl { get; set; }
public string ShortDescription { get; set; }
public double HotelRating { get; set; }
public double TripAdvisorRating { get; set; }
public string RateCurrencyCode { get; set; }
}
public IEnumerable<Hotelsummary> GetHotelsForLocationSearch()
{
var hotelDetails = GetHotelsFromEan.GetListOfHotels();
var root = JObject.Parse(hotelDetails.ToString());
IList<JToken> hotels = root["HotelListResponse"]["HotelList"]["HotelSummary"].Children().ToList();
IList<Hotelsummary> hotelsummaries = hotels.Select(result => JsonConvert
.DeserializeObject<Hotelsummary>(
result.ToString())).ToList();
return hotelsummaries;
}
但是一旦我尝试更深入地挖掘数据,我就无法获得我需要的数据
最佳答案
试试这个:
IList<JToken> rates = root["HotelListResponse"]["HotelList"]["HotelSummary"][0]["RoomRateDetailsList"]["RoomRateDetails"]["RateInfos"].Children().ToList();
编辑:
var rateInfo = json["HotelListResponse"]["HotelList"]["HotelSummary"][0]["RoomRateDetailsList"]["RoomRateDetails"]["RateInfos"]["RateInfo"];
var result =JsonConvert.DeserializeObject<RateInfo>( rateInfo .ToString() );
关于c# - 从深度嵌套的 json 对象获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16079116/
我正在使用python 2.7 当我尝试在其上运行epsilon操作时出现此错误, 这是我的代码 import cv2 import numpy as np img = cv2.imread('img
1 很多程序员对互联网行业中广泛讨论的“35岁危机”表示不满,似乎所有的程序员都有着35岁的职业保质期。然而,随着AI技术的兴起,这场翻天覆地的技术革命正以更加残酷且直接的方式渗透到各行各业。程序员
我有一个包含多个子模块的项目,我想列出每个子模块的相对深度 该项目: main_project submodule1 submodule1\submodule1_1 submo
我有一张彩色图像及其深度图,它们都是由 Kinect 捕获的。我想将它投影到另一个位置(以查看它在另一个视角下的样子)。由于我没有 Kinect 的内在参数(相机参数);我该如何实现? P.S:我正在
给出了这三个网址: 1) https://example.com 2) https://example.com/app 3) https://example.com/app?param=hello 假
这个着色器(最后的代码)使用 raymarching 来渲染程序几何: 但是,在图像(上图)中,背景中的立方体应该部分遮挡粉红色实体;不是因为这个: struct fragmentOutput {
我希望能够在 ThreeJS 中创建一个房间。这是我到目前为止所拥有的: http://jsfiddle.net/7oyq4yqz/ var camera, scene, renderer, geom
我正在尝试通过编写小程序来学习 Haskell...所以我目前正在为简单表达式编写一个词法分析器/解析器。 (是的,我可以使用 Alex/Happy...但我想先学习核心语言)。 我的解析器本质上是一
我想使用像 [parse_ini_file][1] 这样的东西。 例如,我有一个 boot.ini 文件,我将加载该文件以进行进一步的处理: ;database connection sett
我正在使用 Mockito 来测试我的类(class)。我正在尝试使用深度 stub ,因为我没有办法在 Mockito 中的另一个模拟对象中注入(inject) Mock。 class MyServ
我试图在调整设备屏幕大小时重新排列布局,所以我这样做: if(screenOrientation == SCREEN_ORIENTATION_LANDSCAPE) { document
我正在 Ubuntu 上编写一个简单的 OpenGL 程序,它使用顶点数组绘制两个正方形(一个在另一个前面)。由于某种原因,GL_DEPTH_TEST 似乎不起作用。后面的物体出现在前面的物体前面
static FAST_FUNC int fileAction(const char *pathname, struct stat *sb UNUSED_PARAM, void *mo
我有这样的层次结构: namespace MyService{ class IBase { public: virtual ~IBase(){} protected: IPointer
我正在制作一个图片库,需要一些循环类别方面的帮助。下一个深度是图库配置文件中的已知设置,因此这不是关于无限深度循环的问题,而是循环已知深度并输出所有结果的最有效方法。 本质上,我想创建一个 包含系统中
如何以编程方式在树状结构上获取 n 深度迭代器?在根目录中我有 List 每个节点有 Map> n+1 深度。 我已修复 1 个深度: // DEPTH 1 nodeData.forEach(base
我正在构建一个包含大量自定义元素的 Polymer 单页界面。 现在我希望我的元素具有某种主样式,我可以在 index.html 或我的主要内容元素中定义它。可以这样想: index.html
我正在尝试每 25 秒连接到配对的蓝牙设备,通过 AlarmManager 安排,它会触发 WakefulBroadcastReceiver 以启动服务以进行连接。设备进入休眠状态后,前几个小时一切正
假设有一个有默认值的函数: int foo(int x=42); 如果这被其他人这样调用: int bar(int x=42) { return foo(x); } int moo(int x=42)
是否可以使用 Javascript 获取 url 深度(级别)? 如果我有这个网址:www.website.com/site/product/category/item -> depth=4www.w
我是一名优秀的程序员,十分优秀!