我正在尝试使用Newtonsoft反序列化数组,以便在列表框中显示来自基于云的服务器的文件,但无论我尝试什么,我总是得到以下错误:
我尝试使用这样的C#类:
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"
}
]
}
]
我尝试使用这样的C#类:
我尝试使用这样的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; set; }
[JsonProperty("size")]
public string Size { get; set; }
}
[JsonProperty("priv")]
public List List { get; set; }
}
public class List
{
[JsonProperty("file")]
public string File { get; set; }
[JsonProperty("ext")]
public string Ext { get; set; }
[JsonProperty("size")]
public string Size { get; set; }
}
使用以下方法反序列化:
List<list> fetch = Newtonsoft.Json.JsonConvert.DeserializeObject<List<list>>(json);
List
的类? - Marc GravellList
的C#类 - 请避免混淆已经存在的类名。 - t0mm13b