NewtonSoft Json反序列化二维数组

时间:2017-06-22 15:11:01

标签: arrays json json.net json-deserialization

我有以下JSON。

[["NAME","S0101_C01_008EA","S0101_C01_031M","state","county"],
["Alcona County, Michigan",null,"1.1","26","001"],
["Alger County, Michigan",null,"1.7","26","003"],
["Allegan County, Michigan",null,"0.2","26","005"],
["Alpena County, Michigan",null,"0.9","26","007"],
["Antrim County, Michigan",null,"0.9","26","009"],
["Arenac County, Michigan",null,"0.8","26","011"]]

我试图将其反序列化为一个对象数组。我不知道为什么我会这么难过。

我可以使用我需要的信息。

 Dim PopulationByState As List(Of JArray) = JsonConvert.DeserializeObject(Of List(Of JArray))(response)

Dim lst As New List(Of String) 'create a new list to hold the strings

For Each t As JToken In PopulationByState

    For Each i In t.Children()

        ListBox1.Items.Add(i)
    Next

Next 

1 个答案:

答案 0 :(得分:0)

您可以将其反序列化为List(Of List(Of Object))

Dim PopulationByState As List(Of List(Of Object)) = _
    JsonConvert.DeserializeObject(Of List(Of List(Of Object)))(response)

Dim state As List(Of Object)
For Each state In PopulationByState.Skip(1) ' .Skip(1) to skip the header '
    ListBox1.Items.Add(String.Join(vbTab, state))
Next

演示(输出到控制台而不是填充列表框):https://dotnetfiddle.net/XQ3w2Z