Dropbox JSON反序列化器似乎使用了错误的对象类型
本文关键字:错误 对象 类型 反序列化 JSON Dropbox | 更新日期: 2023-09-27 18:04:03
我正在使用DropNetRT尝试与Dropbox集成,但在从Dropbox API反序列化JSON响应时始终得到错误。废话少说:
抛出的异常是Newtonsoft.Json.JsonReaderException occurred
HResult=-2146233088
Message=Error reading string. Unexpected token: StartObject. Path 'entries[0][1]', line 1, position 202.
Source=Newtonsoft.Json
LineNumber=1
LinePosition=202
Path=entries[0][1]
在var deltaResponse = JsonConvert.DeserializeObject<DeltaPageInternal>(responseBody);
responseBody
是什么?是这个家伙(为了方便大家,稍微简化了一下)
{
"has_more": true,
"cursor": "BLAGHABLAGAbigDarn-StringTHing123",
"entries":
[
["/exampleFile.pdf", {"revision": 1, "rev": "1131aa664", "thumb_exists": false, "bytes": 249159, "modified": "Mon, 12 Aug 2013 18:55:30 +0000", "client_mtime": "Mon, 12 Aug 2013 18:55:30 +0000", "path": '"/exampleFole.pdf'", "is_dir": false, "icon": "page_white_acrobat", "root": "dropbox", "mime_type": "application/pdf", "size": "243.3 KB"}],
["/examplefolder", {"revision": 2, "rev": "2131aa664", "thumb_exists": false, "bytes": 0, "modified": "Tue, 13 Aug 2013 17:30:35 +0000", "path": "/examplefolder", "is_dir": true, "icon": "folder_user", "root": "dropbox", "size": "0 bytes"}]
],
"reset": true
}
我怀疑模型DeltaPageInternal
是罪魁祸首,因为条目[0][1]实际上并不是模型所暗示的:
internal class DeltaPageInternal
{
public string Cursor { get; set; }
public bool Has_More { get; set; }
public bool Reset { get; set; }
public List<List<string>> Entries { get; set; }
}
还有人有这个问题吗?从Dropbox收到的反馈来看,这似乎应该是相当普遍的……我调用的是旧版本的API吗?
像往常一样,提前感谢你的专业知识。把你的字符串改成这个,这不是一个有效的json字符串http://json.parser.online.fr/
{
"has_more": true,
"cursor": "BLAGHABLAGAbigDarn-StringTHing123",
"entries": [
[
"exampleFile.pdf",
{
"revision": 1,
"rev": "1131aa664",
"thumb_exists": false,
"bytes": 249159,
"modified": "Mon, 12 Aug 2013 18:55:30 +0000",
"client_mtime": "Mon, 12 Aug 2013 18:55:30 +0000",
"path": "exampleFole.pdf",
"is_dir": false,
"icon": "page_white_acrobat",
"root": "dropbox",
"mime_type": "applicationpdf",
"size": "243.3 KB"
}
],
[
"examplefolder",
{
"revision": 2,
"rev": "2131aa664",
"thumb_exists": false,
"bytes": 0,
"modified": "Tue, 13 Aug 2013 17:30:35 +0000",
"path": "examplefolder",
"is_dir": true,
"icon": "folder_user",
"root": "dropbox",
"size": "0 bytes"
}
]
],
"reset": true
}