难以读取json
有用的返回方式
搜索“遍历”以查找如何创建类以及如何反序列化json返回
这是json返回:
[[{"metadata":{},"contentType":0,"contentId":0,"objectName":"Mi","objectId":"1","classId":"118"},
{"metadata":{},"contentType":0,"contentId":0,"objectName":"BA","objectId":"224445","classId":"103"},
{"metadata":{},"contentType":0,"contentId":0,"objectName":"1","objectId":"239011","classId":"104"},
{"metadata":{},"contentType":0,"contentId":0,"objectName":"1","objectId":"239309","classId":"105"}]]
尝试了Visual Studio(VB.net)选择性粘贴以创建json类,但是我似乎无法理解如何使用它。使用Newtonsoft.Json。
这些是类,如何将json反序列化并使其有用?
Public Class Rootobject
Public Property Property1()() As Class1
End Class
Public Class Class1
Public Property metadata As Metadata
Public Property contentType As Integer
Public Property contentId As Integer
Public Property objectName As String
Public Property objectId As String
Public Property classId As String
End Class
Public Class Metadata
End Class
答案 0 :(得分:0)
您的JSON是Class1
对象数组的数组,因此您需要对此进行反序列化。
Dim data As Class1()() = JsonConvert.DeserializeObject(Of Class1()())(json)
您实际上不需要这里的Rootobject
类。
正在运行的演示:https://dotnetfiddle.net/1JuaYk