JSON解码:意外令牌:StartArray [英] JSON decoding: Unexpected token: StartArray

查看:265
本文介绍了JSON解码:意外令牌:StartArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JSON.net 来解码JSON字符串,我找到此错误:

I'm using JSON.net to decode a JSON string and I find this error:

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

Exception in 'Newtonsoft.Json.JsonReaderException' en Newtonsoft.Json.dll

Informaciónadicional:读取字符串时出错.意外的标记: StartArray.路径提及",第3行,位置3.

Información adicional: Error reading string. Unexpected token: StartArray. Path 'mentions', line 3, position 3.

JSON字符串如下所示:

The JSON string is something like this:

{
"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
}

问题似乎出在第三行,其中[[]开头是提及的数组,我已经看到此错误或多或少是常见的,但没有找到解决方法.

and looks like the problem is in third line where the '[' starts the array of mentions, I've seen this error is more or less common but didn't find a solution.

这是我的代码:

    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)

帮助?

推荐答案

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

It looks like you are trying to deserialize your JSON into a Dictionary(Of String, String). However, clearly the value of mentions is not a String; it is an array of Objects. You could try deserializing into a Dictionary(Of String, Object) instead.

这篇关于JSON解码:意外令牌:StartArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆