gpt4 book ai didi

c# - C# 类中的绑定(bind)(映射)Json

转载 作者:行者123 更新时间:2023-12-02 08:25:54 24 4
gpt4 key购买 nike

我有以下 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"
}

我已将绑定(bind)类设置为:-

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>();

但是当我看到悬停时:-

enter image description here

正如我们在图片中看到的:-

Message obj = new Message();

Obj 正在变为 Null

如何以正确的方式映射它?

编辑1:

我将我的类(class)更改为:-

 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; }
}

同样的问题:- enter image description here

最佳答案

只需更改您的类,以便有一个 message 属性。在你的类中它被称为objmessage 属性也应该是 public 以便可以设置。

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 message { get; set; }
}

public class Message
{
public string StoryID { get; set; }
public string StoryDesc { get; set; }
}

关于c# - C# 类中的绑定(bind)(映射)Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com