我在Json之下: -
{
"EventMessageUId": "ef51b5a3-32b2-e611-baf9-fc3fdb446bd2",
"Message": [{
"StoryID": 1,
"StoryDesc": "xyzzzz"
}],
"ProjectUId": "00100000-0000-0000-0000-000000000000",
"ProjectId": 1,
"CreatedByUser": "system",
"CreatedByApp": "myWizard-Fortress",
"CreatedOn": "2016-11-24T10:44:39.473"
}
我已将绑定类设为: -
public class Requirements
{
public string EventMessageUId { get; set; }
public int ProjectId { get; set; }
public string CreatedByUser { get; set; }
public string CreatedByApp { get; set; }
public string CreatedOn { get; set; }
Message obj = new Message();
}
public class Message
{
public string StoryID { get; set; }
public string StoryDesc { get; set; }
}
我将其映射如下: -
Requirements objRequirement = JsonObject.ToObject<Requirements>();
但是当我看透HOVER时: -
正如我们在图片中看到的那样: -
Message obj = new Message();
Obj
正在变为Null
如何以正确的方式映射?
修改1:
我把班级改为: -
public class Requirements
{
public string EventMessageUId { get; set; }
public int ProjectId { get; set; }
public string CreatedByUser { get; set; }
public string CreatedByApp { get; set; }
public string CreatedOn { get; set; }
public Message Requirement { get; set; }
}
答案 0 :(得分:2)
只需更改您的班级,以便有Select-Object @{
N = "FS_MB";
E = {
[math]::round( ([decimal](($_.FolderSize -replace "[0-9\.]+ [A-Z]* \(([0-9,]+) bytes\)","`$1") -replace ",","") / 1MB),2)
}
}
属性。在您的课程中,它被称为message
。 <{1}}属性也应该是obj
,以便可以设置。
message
答案 1 :(得分:1)
我看到了3个可能的问题:
Message
的{{1}}对象,在您的班级定义中,其名称为Message
obj
对象设置为数组Message
{
"EventMessageUId": "ef51b5a3-32b2-e611-baf9-fc3fdb446bd2",
"Message": {
"StoryID": 1,
"StoryDesc": "xyzzzz"
},
"ProjectUId": "00100000-0000-0000-0000-000000000000",
"ProjectId": 1,
"CreatedByUser": "system",
"CreatedByApp": "myWizard-Fortress",
"CreatedOn": "2016-11-24T10:44:39.473"
}
答案 2 :(得分:1)
按如下方式修改您的第一堂课:
public Message[] Message { get; set; }
答案 3 :(得分:1)
您的Message
课程中需要一个名为Collection
的{{1}}属性(使用List
)。删除Requirements
将此添加到您的班级
Message obj = new Message();
所以你的班级定义必须如此。
public List<Message> Message {get; set;}