C# 使用NewtonSoft反序列化JSON

C# 使用NewtonSoft反序列化JSON,c#,json,json.net,C#,Json,Json.net,尝试反序列化JSON文本时,我收到以下错误: [ [ {"trackingNo":"R2E2003100011429","eventTime":1479184076000,"eventCode":"INF","activity":"Shipping Information received by Australia Post","location":"","referenceTrackingNo":null}, {"trackingNo":"R2E2003

尝试反序列化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...

        }
分析值时遇到意外字符:{.Path'[0]',第1行,位置3

使用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...

        }
[
[
{“trackingNo”:“R2E2003100011429”,“事件时间”:1479184076000,“事件代码”:“INF”,“活动”:“澳大利亚邮政收到的装运信息”,“位置”:“referenceTrackingNo”:null},
{“trackingNo”:“R2E2003100011429”,“eventTime”:1479186149000,“eventCode”:“INF”,“activity”:“Shipping Information approved by Australia Post”,“location”:“referenceTrackingNo”:null},
{“跟踪号”:“R2E2003100011429”,“事件时间”:1479448620000,“事件代码”:“SCN”,“活动”:“离开的设施”,“位置”:“引用跟踪号”:null}
],
[
{“trackingNo”:“HBF0003142011420”,“事件时间”:1478666798000,“事件代码”:“INF”,“活动”:“澳大利亚邮政收到的装运信息”,“位置”:“referenceTrackingNo”:null},
{“trackingNo”:“HBF0003142011420”,“eventTime”:1478732453000,“eventCode”:“INF”,“activity”:“Shipping Information approved by Australia Post”,“location”:“referenceTrackingNo”:null},
{“跟踪号”:“HBF0003142011420”,“事件时间”:1478932980000,“事件代码”:“SCN”,“活动”:“离开的设施”,“位置”:“引用跟踪号”:null},
{“跟踪号”:“HBF0003142011420”,“事件时间”:1479082255000,“事件代码”:“SCN”,“活动”:“到达目的地国家/地区的设施”,“位置”:“参考跟踪号”:null},
{“跟踪号”:“HBF0003142011420”,“事件时间”:1479082261000,“事件代码”:“CCD”,“活动”:“海关清关”,“地点”:“参考跟踪号”:null},
{“trackingNo”:“HBF0003142011420”,“事件时间”:147912411800,“事件代码”:“SCN”,“活动”:“通过澳大利亚邮政设施处理”,“地点”:“CHULLORA NSW”,“referenceTrackingNo”:null},
{“trackingNo”:“HBF0003142011420”,“eventTime”:1479236805000,“eventCode”:“SCN”,“activity”:“澳大利亚邮政今日交货”,“location”:“KINGSGROVE NSW”,“referenceTrackingNo”:null},
{“trackingNo”:“HBF0003142011420”,“eventTime”:1479248135000,“eventCode”:“DLD”,“activity”:“Delivered”,“location”:“CARINGBAH NSW”,“referenceTrackingNo”:null}
]
]
这是我的密码:
使用(StreamReader=newstreamreader(webResponse.GetResponseStream())
{
string text=reader.ReadToEnd();
List trackingResponse=JsonConvert.DeserializeObject(文本);
//…做些事情。。。
}

您应该使用的类型是
List

var result=JsonConvert.DeserializeObject(json);
公共类对象
{
公共字符串跟踪no{get;set;}
公共长事件时间{get;set;}
公共字符串事件代码{get;set;}
公共字符串活动{get;set;}
公共字符串位置{get;set;}
公共字符串referenceTrackingNo{get;set;}
}

您应该使用的类型是
List

var result=JsonConvert.DeserializeObject(json);
公共类对象
{
公共字符串跟踪no{get;set;}
公共长事件时间{get;set;}
公共字符串事件代码{get;set;}
公共字符串活动{get;set;}
公共字符串位置{get;set;}
公共字符串referenceTrackingNo{get;set;}
}

LB访问内容的最佳方法是什么,例如,
result[0][0]。trackingNo
LB访问内容的最佳方法是什么,例如,
result[0][0]。trackingNo