如何使用类修饰在嵌套对象中选择json值“ estimatedLocationDate”?属性“ estimatedLocationDate”总是返回null
而不是value 2015-10-01T14:00:00.000
。其他修饰值返回正确的值。
这是我的C#
课
public string id { get; set; }
public string name { get; set; }
[JsonProperty("publishedDate")]
public string publishdate { get; set; }
[JsonProperty("estimatedLocationDate")]
public string estimatedLocationDate{ get; set; }
[JsonProperty("createdTime")]
public string createtime { get; set; }
[JsonProperty("lastUpdatedTime")]
public string lastupdate { get; set; }
这是 JSON
"planet": [
{
"id": "123456",
"planetid": "en-us/Jupiter-mars/---main",
"name": "The planet Mercury",
"description": "This is placeholder for the description",
"publishedDate": "2013-10-14T23:30:00.000",
"createtime": "2012-03-01T14:00:00.000",
"product": {
"moreid": "1427-48-bd-9-113",
"color": "200",
"imageUrl": "http://image.bing.com/Mercury.jpg",
"neighbor": [
{
"ring": "Two",
"moons": 2
}
],
"estimatedLocationDate": "2014-10-01T14:00:00.000"
},
您的班级应该看起来像这样(但这是不完整的):
class Planet
{
[JsonProperty("planet")]
PlanetInfo[] planet { get; set; }
}
class Product
{
[JsonProperty("estimatedLocationDate")]
string estimatedLocationDate {get;set;}
}
class PlanetInfo
{
public string id { get; set; }
public string name { get; set; }
[JsonProperty("publishedDate")]
public string publishdate { get; set; }
[JsonProperty("estimatedLaunchDate")]
public string estimatedLaunchDate { get; set; }
[JsonProperty("createdTime")]
public string createtime { get; set; }
[JsonProperty("lastUpdatedTime")]
public string lastupdate { get; set; }
[JsonProperty("product")]
public Product product { get; set; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句