【发布时间】:2019-09-22 06:48:08
【问题描述】:
我有一个 JSON 字符串,我正在尝试将其反序列化为 .Net 对象。
代码一直有效,直到遇到嵌套数组。然后它只返回空值。
在下面的示例中,当我调试和查看处理后的对象时,它只会有:
规则:
0: Will contain all data for the first node (project_number)
1: Will contain all data for the second node (agreement_number)
2: All fields will be Nothing
Condition: AND
Valid: true
如何反序列化整个对象?请注意,JSON 字符串来自一个库 (https://querybuilder.js.org/),所以我对如何创建字符串犹豫不决。
这是我的代码:
Dim TestObj = JsonConvert.DeserializeObject(Of List(Of JsonObject))(TestString)
<Serializable()>
Public Class JsonObject
Public Property condition As String
Public Property Rules As List(Of Rules)
Public Property valid As Boolean
End Class
<Serializable()>
Public Class Rules
Public Property id As String
Public Property field As String
Public Property type As String
Public Property input As String
Public Property [operator] As String
Public Property value As String
End Class
Public Property TestString As String = "[
{
'condition':'AND',
'rules':[
{
'id':'project_number',
'field':'project_number',
'type':'string',
'input':'text',
'operator':'equal',
'value':'dfgdfs'
},
{
'id':'agreement_number',
'field':'agreement_number',
'type':'string',
'input':'text',
'operator':'contains',
'value':'asdfas'
},
{
'condition':'AND',
'rules':[
{
'id':'division',
'field':'division',
'type':'string',
'input':'select',
'operator':'in',
'value':[
'0',
'11719'
]
},
{
'condition':'AND',
'rules':[
{
'id':'ta',
'field':'ta',
'type':'string',
'input':'select',
'operator':'in',
'value':[
'24740',
'24744'
]
}
]
}
]
}
],
'valid':true
}]"
【问题讨论】:
标签: asp.net json vb.net json.net jquery-query-builder