我是 JSON 字符串的新手,所以我很难使用它。我习惯了 SOAP Web 服务,其中 Visual Studio 会在后台自动为我创建强类型类。
JSON - REST Web 服务对我来说非常乏味,因为我必须手动创建等效的强类型类。(或者我可能错了)。
我有一个 REST Web 服务返回给我的这个 JSON 字符串:
{"Message":"请求无效。","ModelState":{"command":["在 JSON 中找不到必需的属性 'Vendor'。路径 '',第 1 行,位置 310。"],"command。条款":["条款字段是必需的。"]}}
你能指导我学习同等课程吗?
感谢您的帮助!
问候, 杰克
假设您使用的是 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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句