JSON decoding: Unexpected token: StartArray

雨燕双飞 提交于 2019-12-06 20:33:31

问题


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

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

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

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.

This is my code:

    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)

Help?


回答1:


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.



来源:https://stackoverflow.com/questions/17972326/json-decoding-unexpected-token-startarray

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!