小编Zeq*_*Zeq的帖子

C#Newtonsoft反序列化JSON数组

我正在尝试使用Newtonsoft对数组进行反序列化,因此我可以在列表框中显示来自基于云的服务器的文件,但无论我尝试什么,我总是会收到此错误:

Newtonsoft.Json.JsonReaderException:'解析值时遇到意外的字符:[.路径'[0] .priv',第4行,第15位.'

这是一个尝试反序列化的示例:

[
 {
  "code": 200,
  "priv": [
     {
        "file": "file.txt",
        "ext": "txt",
        "size": "104.86"
     },
     {
        "file": "file2.exe",
        "ext": "exe",
        "size": "173.74"
     },

  ],
  "pub": [
     {
        "file": "file.txt",
        "ext": "txt",
        "size": "104.86"
     },
     {
        "file": "file2.exe",
        "ext": "exe",
        "size": "173.74"
     }
  ]
 }
]
Run Code Online (Sandbox Code Playgroud)

我尝试使用像这样的C#类:

    public class ListJson
{
    [JsonProperty("pub")]
    public List List { get; set; }
}

public class List
{
    [JsonProperty("file")]
    public string File { get; set; }

    [JsonProperty("ext")]
    public string Ext { get; …
Run Code Online (Sandbox Code Playgroud)

c# serialization json json.net deserialization

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

标签 统计

c# ×1

deserialization ×1

json ×1

json.net ×1

serialization ×1