JSON - 转换为 VB.NET 对象
JSON - Conversion to VB.NET Object
我是 JSON 字符串的新手,所以我很难使用它。
我习惯了 SOAP Web 服务,其中 Visual Studio 在后台自动为我创建强类型 Classes。
JSON - REST Web 服务对我来说非常乏味,因为我必须手动创建等效的强类型 Classes。 (或者我可能错了)。
REST Web 服务返回给我的 JSON 字符串:
{"Message":"The request is invalid.","ModelState":{"command":["Required property 'Vendor' not found in JSON. Path '', line 1, position 310."],"command.Terms":["The Terms field is required."]}}
你能指导我等效的 Class 吗?
感谢您的帮助!
此致,
杰克
假设您正在使用 JSON.NET...
Public Class Response
Public Property Message As String
Public Property ModelState As ModelState
End Class
Public Class ModelState
<JsonProperty("command")>
Public Property Command As List(Of String) = New List(Of String)
<JsonProperty("command.Terms")>
Public Property Terms As List(Of String) = New List(Of String)
End Class
用法:
Dim response As Response = JsonConvert.DeserializeObject(jsonString)
我是 JSON 字符串的新手,所以我很难使用它。 我习惯了 SOAP Web 服务,其中 Visual Studio 在后台自动为我创建强类型 Classes。
JSON - REST Web 服务对我来说非常乏味,因为我必须手动创建等效的强类型 Classes。 (或者我可能错了)。
REST Web 服务返回给我的 JSON 字符串:
{"Message":"The request is invalid.","ModelState":{"command":["Required property 'Vendor' not found in JSON. Path '', line 1, position 310."],"command.Terms":["The Terms field is required."]}}
你能指导我等效的 Class 吗?
感谢您的帮助!
此致, 杰克
假设您正在使用 JSON.NET...
Public Class Response
Public Property Message As String
Public Property ModelState As ModelState
End Class
Public Class ModelState
<JsonProperty("command")>
Public Property Command As List(Of String) = New List(Of String)
<JsonProperty("command.Terms")>
Public Property Terms As List(Of String) = New List(Of String)
End Class
用法:
Dim response As Response = JsonConvert.DeserializeObject(jsonString)