小编how*_*doI的帖子

将字符串转换为类型“System.Text.Json.JsonElement”时出错

我有一个类,其中我在从 json 文件填充 jsonElement 时遇到一些问题

{
    "entities": [
        {
            "name": "DateTimeENT1",
            "description": "This a  example",
            "uil": {
                      "uill": "This is my Layout"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

正在被反序列化到此类中:

public class Container {

    public ICollection<Entity> Entities {get; set;}
}


public class Entity {
    public string Name {get; set;}
    public string Descripton {get; set;}
    UIL Uil {get; set;}
}

public class UIL{
    JsonElement Uill {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

这就是我反序列化它的方式:

var input= JsonConvert.DeserializeObject<Container>(File.ReadAllText(@"init.json"));
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到一条错误消息'Error converting value "This is my Layout" to type 'System.Text.Json.JsonElement'. 我该如何克服这个问题? …

c# json asp.net-core json-serialization

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

c# ×1

json ×1

json-serialization ×1