无法反序列化Jason文件,但得到了响应结果



jason file =

{
"educations": {
"count": 23,
"education": [{
"studId": "",
"joinDate": "2021-04-08 12:22",
"regDate": "2021-04-08 12:23",
"enrolled": false,
"eduId": "1-eassasa7",
"pId": "dfdgdfg456fghf",
"startDate": "2021-09-03",
"expiry": {
"monthlyExpire": true
},
"reRegistration": "OPTIONAL",
"refreeId1": "",
"refreeId2": "",
"tutor": true,
"libraryAllowed": true,
"sports": "ENABLE",
"sendNotification": true,
"ccEmail": "",
"isTest": false,
"SportsGroup"

上面的是我的jason,我可以把它放到响应

string rawResponse = apiDataResponse.Content;
var result = JsonConvert.DeserializeObject<RootData>(rawResponse);

下面是我的类

RootData
{
[JsonProperty(PropertyName ="educations")]
public education[] edu1 { get; set; } 
}
class educationss
{
public int count { get; set; }    
[JsonProperty(PropertyName="education")]
public education[] edu { get; set; }    
}

class education
{         
public string studId { get; set; }      
public DateTime joinDate { get; set; }
public DateTime regDate { get; set; }
public bool enrolled { get; set; }
public string eduId { get; set; }
public string pId { get; set; }
public DateTime startDate { get; set; }
public expiry[] monthlyExpire { get; set; }
public string reRegistration { get; set; }
public string refreeId1 { get; set; }
public string refreeId2 { get; set; }
public bool tutor { get; set; }
public bool LibraryAllowed { get; set; }
public string sports { get; set; }
public bool sendNotification { get; set; }
public string ccEmail { get; set; }
public bool isTest { get; set; }
public sportGroup[] sportGroup { get; set; }
}

但是我无法为我的结果变量获得任何值,它显示为null。

Can you please help me?

try this

var json= ...json string
var jsonDeserialized = JsonConvert.DeserializeObject<DataRoot>(json); 
jsonDeserialized.educations.education.ForEach(e =>
{
Console.WriteLine($"joinDate: {e.joinDate.ToString()},   pid: {e.pId}");
});

public class DataRoot
{
public Educations educations { get; set; }
}

public class Educations
{
public int count { get; set; }
public List<Education> education { get; set; }
}
public class Education
{
public string studId { get; set; }
public string joinDate { get; set; }
public string regDate { get; set; }
public bool enrolled { get; set; }
public string eduId { get; set; }
public string pId { get; set; }
public string startDate { get; set; }
public Expiry expiry { get; set; }
public string reRegistration { get; set; }
public string refreeId1 { get; set; }
public string refreeId2 { get; set; }
public bool tutor { get; set; }
public bool libraryAllowed { get; set; }
public string sports { get; set; }
public bool sendNotification { get; set; }
public string ccEmail { get; set; }
public bool isTest { get; set; }
public object SportsGroup { get; set; }
}
public class Expiry
{
public bool monthlyExpire { get; set; }
}

你必须修改json

{
"educations": {
"count": 23,
"education": [
{
"studId": "",
"joinDate": "2021-04-08 12:22",
"regDate": "2021-04-08 12:23",
"enrolled": false,
"eduId": "1-eassasa7",
"pId": "dfdgdfg456fghf",
"startDate": "2021-09-03",
"expiry": {
"monthlyExpire": true
},
"reRegistration": "OPTIONAL",
"refreeId1": "",
"refreeId2": "",
"tutor": true,
"libraryAllowed": true,
"sports": "ENABLE",
"sendNotification": true,
"ccEmail": "",
"isTest": false,
"SportsGroup": null
}
]
}
}

最新更新