如何从 JSON 字符串中删除空数组和空列表?
我使用 vb.net 和 json.net 来做这个,但是 json.net 不能从 JSON 字符串中删除空数组。我的 JSON 字符串是这样的:
{
"jsonrpc": "2.0",
"id": 1,
"token": "tikenname",
"method": "task.run",
"params": {
"commandList": [{
"method": "Users.new",
"params": {
"userIds": "userid",
"details": {
"credentials": {
"userName": "user",
"password": "pass"
},
"data": {
"rights": {},
"quota": {
"daily": {
"limit": {}
},
"weekly": {
"limit": {}
},
"monthly": {
"limit": {}
}
},
"wwwFilter": {}
},
"autoLogin": {
"addresses": {},
"addressGroup": {}
},
"vpnAddress": {},
"groups": {}
}
}
},
{
"method": "set.save"
}
]
}
}
例如我想从我的字符串中删除这个部分
"data": {
"rights": {},
"quota": {
"daily": {
"limit": {}
},
"weekly": {
"limit": {}
},
"monthly": {
"limit": {}
}
},
"wwwFilter": {}
},
"autoLogin": {
"addresses": {},
"addressGroup": {}
},
"vpnAddress": {},
"groups": {}
这是我的课:
Public Class Account
Public Property jsonrpc As String
Public Property id As Integer
Public Property token As String
Public Property method As String
Public Property params As New AccountSetParams
End Class
Public Class AccountSetParams
Public Property commandList As New List(Of AccountSetCommandlist)
End Class
Public Class AccountSetCommandlist
Public Property method As String
Public Property params As New AccountSetUserDetails
End Class
Public Class AccountSetUserDetails
Public Property userIds() As String
Public Property details As New AccountSetDetails
Public Property domainId As String
End Class
Public Class AccountSetDetails
Public Property credentials As New AccountSetCredentials
Public Property fullName As String
Public Property data As New AccountSetData
Public Property autoLogin As New AccountSetAutologin
Public Property vpnAddress As New AccountSetVpnaddress
Public Property groups() As New AccountSetGroup
End Class
...