10

我正在使用JSON.net解码 JSON 字符串,我发现这个错误:

'Newtonsoft.Json.JsonReaderException' 中的异常 en Newtonsoft.Json.dll

信息 adicional: 读取字符串时出错。意外令牌:StartArray。路径“提及”,第 3 行,位置 3。

JSON 字符串是这样的:

{
"mentions":
    [
        {
            "id":"1234",
            "alert_id":123,
            "title":"Bla bla bla",
            "url":"http:\/\/www.example.com\/",
            "unique_id":"123",
            "published_at":"2013-07-30T11:26:36.92131100+00:00",
            "created_at":"2013-07-30T11:27:08.0+00:00",
            "updated_at":"2013-07-30T11:27:09.0+00:00",
            "favorite":false,
            "trashed":false,
            "trashed_set_by_user":false,
            "read":false,
            "tone":0,
            "tone_score":0.14732,
            "relevance_score":1,
            "source_type":"forums",
            "source_name":"xxx",
            "source_url":"http:\/\/example.com\/",
            "language_code":"es",
            "tasks":[],
            "logs":[],
            "children":[],
            "picture_url":"https:\/\/example.com\/example.jpg"
        },
        {
            "id":"1235",
            "alert_id":123,
            "title":"Bla bla bla",
            "url":"http:\/\/www.example.com\/",
            "unique_id":"124",
            "published_at":"2013-07-30T11:26:36.92131100+00:00",
            "created_at":"2013-07-30T11:27:08.0+00:00",
            "updated_at":"2013-07-30T11:27:09.0+00:00",
            "favorite":false,
            "trashed":false,
            "trashed_set_by_user":false,
            "read":false,
            "tone":0,
            "tone_score":0.14732,
            "relevance_score":1,
            "source_type":"forums",
            "source_name":"xxx",
            "source_url":"http:\/\/example.com\/",
            "language_code":"es",
            "tasks":[],
            "logs":[],
            "children":[],
            "picture_url":"https:\/\/example.com\/example.jpg"
        }
    ],
"recently_reenabled":false
}

看起来问题出在“[”开始提及数组的第三行,我看到这个错误或多或少很常见,但没有找到解决方案。

这是我的代码:

    Dim result As New Dictionary(Of String, String)
    Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer
    Dim jsonString As String

    jsonString = txtJSON.Text

    result = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(jsonString)

帮助?

4

1 回答 1

13

看起来您正在尝试将 JSON 反序列化为Dictionary(Of String, String). 但是,显然 的值mentions不是String; 它是一个对象数组。您可以尝试反序列化为 a Dictionary(Of String, Object)

于 2013-07-31T14:31:59.123 回答