NewtonSoft.JSON 反序列化 - 反序列化不正确。 (VB.NET)
NewtonSoft.JSON Deserialize - Not deserializing correctly. (VB.NET)
我正在尝试反序列化 JSON return 但是当我尝试在最高级别反序列化时它要么出错,要么不出错,只是 return 为 null如果我开始更深入 json.
我只得到“null”returns 用于其余的反序列化 - 我已经成功地分别反序列化 messages
但是当我尝试做全部时它只是 return我的所有值都为空。
当我尝试在 response
处反序列化时,它提供了错误,我不清楚究竟是什么错误。
型号
Public Class response
public property http_code as string
public property response_code as string
public property response_msg as string
public property data as smsdata
End Class
Public Class smsdata
public property total_price as string
public property total_count as string
public property queued_count as string
public property messages as messages
End Class
Public Class messages
Public property messages as list(of message)
End Class
Public Class message
Public Property direction as string
<JsonProperty("date")>
Public property daterange as string
<JsonProperty("to")>
public property recipient as string
public property body as string
public property from as string
public property schedule as string
public property message_id as string
public property message_parts as string
public property message_price as string
public property from_email as string
public property list_id as string
public property custom_string as string
public property contact_id as string
public property user_id as string
public property subaccount_id as string
public property country as string
public property carrier as string
public property status as string
End Class```
Module Program
Sub Main(args As String())
dim jsonstring as string = "{ 'http_code': 200, 'response_code': 'SUCCESS', 'response_msg': 'Messages queued for delivery.', 'data': { 'total_price': 0.0516, 'total_count': 2, 'queued_count': 2, 'messages': [ { 'direction': 'out', 'date': 1637744634, 'to': '+44771111111111', 'body': 'test message, please ignore 1', 'from': 'Shield', 'schedule': 1637744634, 'message_id': 'A3F48CA8-79E6-416F-A8C6-7660BD7B7632', 'message_parts': 1, 'message_price': '0.0258', 'from_email': null, 'list_id': null, 'custom_string': '', 'contact_id': null, 'user_id': 100525, 'subaccount_id': 116285, 'country': 'GB', 'carrier': 'O2', 'status': 'SUCCESS' }, { 'direction': 'out', 'date': 1637744634, 'to': '+4477222222222', 'body': 'test message, please ignore 2', 'from': 'Clubcare', 'schedule': 1637744634, 'message_id': '670E96E2-ED4F-4FAB-8594-D49B244EA2C3', 'message_parts': 1, 'message_price': '0.0258', 'from_email': null, 'list_id': null, 'custom_string': '', 'contact_id': null, 'user_id': 100525, 'subaccount_id': 116285, 'country': 'GB', 'carrier': 'O2', 'status': 'SUCCESS' } ], '_currency': { 'currency_name_short': 'GBP', 'currency_prefix_d': '£', 'currency_prefix_c': 'p', 'currency_name_long': 'British Pounds' } } }"
dim results = JsonConvert.DeserializeObject(Of response)(jsonstring)
End Sub
End Module
正在检查您的代码和示例数据:
Public Class smsdata
public property total_price as string
public property total_count as string
public property queued_count as string
public property messages as List (Of message)
End Class
应该可以解决问题,您可以转储消息 Class
(从单个问题开始:我从未使用过它们,但是 VS-Code 将它们标记为错误,但是 :-))
我正在尝试反序列化 JSON return 但是当我尝试在最高级别反序列化时它要么出错,要么不出错,只是 return 为 null如果我开始更深入 json.
我只得到“null”returns 用于其余的反序列化 - 我已经成功地分别反序列化 messages
但是当我尝试做全部时它只是 return我的所有值都为空。
当我尝试在 response
处反序列化时,它提供了错误,我不清楚究竟是什么错误。
型号
Public Class response
public property http_code as string
public property response_code as string
public property response_msg as string
public property data as smsdata
End Class
Public Class smsdata
public property total_price as string
public property total_count as string
public property queued_count as string
public property messages as messages
End Class
Public Class messages
Public property messages as list(of message)
End Class
Public Class message
Public Property direction as string
<JsonProperty("date")>
Public property daterange as string
<JsonProperty("to")>
public property recipient as string
public property body as string
public property from as string
public property schedule as string
public property message_id as string
public property message_parts as string
public property message_price as string
public property from_email as string
public property list_id as string
public property custom_string as string
public property contact_id as string
public property user_id as string
public property subaccount_id as string
public property country as string
public property carrier as string
public property status as string
End Class```
Module Program
Sub Main(args As String())
dim jsonstring as string = "{ 'http_code': 200, 'response_code': 'SUCCESS', 'response_msg': 'Messages queued for delivery.', 'data': { 'total_price': 0.0516, 'total_count': 2, 'queued_count': 2, 'messages': [ { 'direction': 'out', 'date': 1637744634, 'to': '+44771111111111', 'body': 'test message, please ignore 1', 'from': 'Shield', 'schedule': 1637744634, 'message_id': 'A3F48CA8-79E6-416F-A8C6-7660BD7B7632', 'message_parts': 1, 'message_price': '0.0258', 'from_email': null, 'list_id': null, 'custom_string': '', 'contact_id': null, 'user_id': 100525, 'subaccount_id': 116285, 'country': 'GB', 'carrier': 'O2', 'status': 'SUCCESS' }, { 'direction': 'out', 'date': 1637744634, 'to': '+4477222222222', 'body': 'test message, please ignore 2', 'from': 'Clubcare', 'schedule': 1637744634, 'message_id': '670E96E2-ED4F-4FAB-8594-D49B244EA2C3', 'message_parts': 1, 'message_price': '0.0258', 'from_email': null, 'list_id': null, 'custom_string': '', 'contact_id': null, 'user_id': 100525, 'subaccount_id': 116285, 'country': 'GB', 'carrier': 'O2', 'status': 'SUCCESS' } ], '_currency': { 'currency_name_short': 'GBP', 'currency_prefix_d': '£', 'currency_prefix_c': 'p', 'currency_name_long': 'British Pounds' } } }"
dim results = JsonConvert.DeserializeObject(Of response)(jsonstring)
End Sub
End Module
正在检查您的代码和示例数据:
Public Class smsdata
public property total_price as string
public property total_count as string
public property queued_count as string
public property messages as List (Of message)
End Class
应该可以解决问题,您可以转储消息 Class
(从单个问题开始:我从未使用过它们,但是 VS-Code 将它们标记为错误,但是 :-))