我想读取下面的Json对象中的子元素。以下是Json示例。我想在testdata1, testdata2 and testdata3.
c#Json读取子对象
{
"HasErrors": false,
"Includes": {
"test ": {
"testdata1": {
"ReviewStatistics": {
"RecommendedCount": 0,
"TotalReviewCount": 2
}
},
"testdata2": {
"ReviewStatistics": {
"RecommendedCount": 0,
"TotalReviewCount": 2
}
},
"testdata3": {
"ReviewStatistics": {
"RecommendedCount": 0,
"TotalReviewCount": 2
}
}
}
}
}
阅读RecommendedCount
和TotalReviewCount
我尝试下面的代码。
RecommendedCount = apiResponse.Includes.Products[key].ReviewStatistics.RecommendedCount,
TotalReviewCount = apiResponse.Includes.Products[key].ReviewStatistics.TotalReviewCount
但是,这是非常缓慢的,因为Json响应超过1000行,因此需要时间。我想知道是否有任何linq我可以用来找到相关数据或我可以使用的其他方法?
在此先感谢。
var jObj = (JObject)JsonConvert.DeserializeObject(rawJson);
foreach (var child in jObj["test"].Children())
{
}
以上是我正在尝试使用的反序列化代码,但得到了Object reference not set to an instance of an object
。错误
你能告诉我们用于反序列化的代码吗? –