JSON解码:意外的令牌:StartArray

时间:2013-07-31 13:51:29

标签: .net json json.net

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

  

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

     

Informaciónadicional:读取字符串时出错。意外的标记:   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)

帮助?

1 个答案:

答案 0 :(得分:13)

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