JSON反序列化列表列表

JSON反序列化列表列表,json,vb.net,list,tuples,deserialization,Json,Vb.net,List,Tuples,Deserialization,我在反序列化以下JSON字符串时遇到问题: {“error”:null,“id”:1234,“result”:[[[[“config.param1”,“111”],[“config.param2”,“1222”]],“config System”,1234]} 我的结构是: Public Structure stuConResponse Dim [Error] As String Dim ID As String Dim Result As List(Of stuSubResult

我在反序列化以下JSON字符串时遇到问题:

{“error”:null,“id”:1234,“result”:[[[[“config.param1”,“111”],[“config.param2”,“1222”]],“config System”,1234]}

我的结构是:

 Public Structure stuConResponse
  Dim [Error] As String
  Dim ID As String
  Dim Result As List(Of stuSubResults)
 End Structure


 Public Structure stuSubResults
  Public Property X1 As List(Of List(Of String))
  Public Property X2 As String
  Public Property X3 As String
 End Structure
我的代码是:

  Dim JSonSettings As New Newtonsoft.Json.JsonSerializerSettings
  JSonSettings.CheckAdditionalContent = True
  JSonSettings.DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTime
  JSonSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore
  JSonSettings.FloatFormatHandling = Newtonsoft.Json.FloatFormatHandling.DefaultValue
  JSonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore

Dim HeloResponse As Structures.stuConResponse = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Structures.stuConResponse)(ReceivedData, JSonSettings)
我试着让“结果”如下:

1) 一个元组(列表(字符串列表),字符串,字符串))

2) (字符串的列表)

3) 其他列表和元组组合

就我个人而言,我无论如何都不能反序列化“结果”对象

我在读取错误和ID时没有问题,但是当结果出现时,我得到一个错误,JSON不能这样做

我也不介意“result”是否可以进入一个未反序列化的字符串,在那里我可以执行一些手动逻辑,但这也不起作用,因为JSON试图变得过于复杂

换句话说,问题是让JSON读取“[[[X1,Y1],[X2,Y2],X3,X4]”,注意它是一个列表/数组,并且它没有任何键名,这就是问题所在(我认为)

如果你能想到这一点,那就太好了

谢谢

您可以决定要对对象执行的操作


您可以将ii转换为字典,然后使用(“键”)获取内容,但如果数据保持不变,我看不出有什么意义。

最后,我解决了它!我不知道您可以使用IDICTIONARY读取整个内容,然后将其分解为ILISTs

对于任何有相同问题的人,以下是解决方案:

1) 代码:

2) 结构:

Public Structure stuConPolSubscribeResponse
 Dim [Error] As String
 Dim ID As String
 Dim ConfigItems As List(Of Dictionary(Of String, String))
End Structure
根据我最初的问题,这项工作和我想要的完全一样。例如,读取一个或多个列表,其中主列表有另外两个不同的元素(一个字符串和一个整数)。iDictionary将读取整个内容,没有任何错误,然后您可以使用ILIST进行迭代

不要问我为什么源JSON字符串是以这种方式编写的……但现在可以读取它了


…我需要一杯咖啡…

Hi CruleD,感谢您的回复,系统在反序列化对象上崩溃,因此无法访问debug.print。此外,您正在使用Java库,而上面的代码是关于NewtonSoft JSON和一些VB.NET代码。我最初的问题是找到一种方法来阻止它崩溃,无论如何,我解决了下面是它。啊,是的,忘记了导入System.Web.Script.Serialization“以便更容易阅读JSON(+对System.Web.Extensions库的引用)。尽管它应该是相同的,无论您使用哪一个。
  Dim I As Integer
  Dim ConPolConfig As Structures.stuConPolSubscribeResponse = Nothing

  Dim dicItems As IDictionary = Newtonsoft.Json.JsonConvert.DeserializeObject(Of IDictionary)(ReceivedData, JSonSettings)
  ConPolConfig.ID = dicItems("id")
  ConPolConfig.Error = dicItems("error")

  If Not dicItems("result") Is Nothing Then
   ConPolConfig.ConfigItems = New List(Of Dictionary(Of String, String))

   Dim ConfigProperties As IList = dicItems("result")(0)
   Dim ConfSysReader As String = dicItems("result")(1)
   Dim Token As Integer = dicItems("result")(2)

   Dim ParamKey As String
   Dim ParamVal As String

   Dim Dic As New Dictionary(Of String, String)

   For I = 0 To ConfigProperties.Count - 1
    ParamKey = ConfigProperties(I)(0)
    ParamVal = ConfigProperties(I)(1)

    Dic.Add(ParamKey, ParamVal)

    ConPolConfig.ConfigItems.Add(Dic)
   Next
  End If
Public Structure stuConPolSubscribeResponse
 Dim [Error] As String
 Dim ID As String
 Dim ConfigItems As List(Of Dictionary(Of String, String))
End Structure