简体   繁体   English

使用NewtonSoft反序列化JSON

[英]deserializing JSON using NewtonSoft

I'm receiving the following error when I attempt to deserialize JSON text: 尝试反序列化JSON文本时收到以下错误:

Unexpected character encountered while parsing value: {. 解析值{时遇到意外字符。 Path '[0]', line 1, position 3. 路径“ [0]”,第1行,位置3。

The JSON Text validated properly using JSONLint.com, here is the JSON text: 使用JSONLint.com正确验证了JSON文本,这是JSON文本:

[
    [
        {"trackingNo":"R2E2003100011429","eventTime":1479184076000,"eventCode":"INF","activity":"Shipping Information received by Australia Post","location":"","referenceTrackingNo":null},
        {"trackingNo":"R2E2003100011429","eventTime":1479186149000,"eventCode":"INF","activity":"Shipping Information approved by Australia Post","location":"","referenceTrackingNo":null},
        {"trackingNo":"R2E2003100011429","eventTime":1479448620000,"eventCode":"SCN","activity":"Departed facility","location":"","referenceTrackingNo":null}
    ],
    [
        {"trackingNo":"HBF0003142011420","eventTime":1478666798000,"eventCode":"INF","activity":"Shipping Information received by Australia Post","location":"","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1478732453000,"eventCode":"INF","activity":"Shipping Information approved by Australia Post","location":"","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1478932980000,"eventCode":"SCN","activity":"Departed facility","location":"","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1479082255000,"eventCode":"SCN","activity":"Arrived at facility in destination country","location":"","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1479082261000,"eventCode":"CCD","activity":"Cleared by customs","location":"","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1479124118000,"eventCode":"SCN","activity":"Processed through Australia Post facility","location":"CHULLORA NSW","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1479236805000,"eventCode":"SCN","activity":"With Australia Post for delivery today","location":"KINGSGROVE NSW","referenceTrackingNo":null},
        {"trackingNo":"HBF0003142011420","eventTime":1479248135000,"eventCode":"DLD","activity":"Delivered","location":"CARINGBAH NSW","referenceTrackingNo":null}
    ]
]

Here is my code:

                    using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
                        {
                            string text = reader.ReadToEnd();
                                List<string[]> trackingResponse = JsonConvert.DeserializeObject<List<string[]>>(text);
//    ...Do some stuff...

        }

The type you should use is List<List<SomeObject>> 您应该使用的类型是List<List<SomeObject>>

var result = JsonConvert.DeserializeObject<List<List<SomeObject>>>(json);


public class SomeObject
{
    public string trackingNo { get; set; }
    public long eventTime { get; set; }
    public string eventCode { get; set; }
    public string activity { get; set; }
    public string location { get; set; }
    public string referenceTrackingNo { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM