0

我正在使用 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应该归咎于模型,因为 entries[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 版本还是什么?

像往常一样,提前感谢您提供的任何专业知识。

4

1 回答 1

-1

将您的字符串更改为此,它不是有效的 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
}
于 2014-05-20T01:29:38.190 回答