0

Having trouble to read json return in a useful way

Searching "all over" to find how to create classes and how to de-serialize json return

This is the json return:

[[{"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"}]]

Tried Visual Studio (VB.net) Paste Special to create json classes, but I can't seem to get my head around how to use it. Using Newtonsoft.Json.

These are the classes, how do I deserialize json and make it useful?

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
10
  • Seems posting does not consider my line breaks when pasting...
    – Lars H
    Aug 7, 2019 at 14:02
  • Dvyn Resh fixed it for you. To get the line breaks verbatim, you need to use code blocks, either with three back ticks on the line before and the line after the code, or by selecting the code block with the mouse and clicking the {} icon.
    – joanis
    Aug 7, 2019 at 14:08
  • This might help: stackoverflow.com/questions/8118019/vb-net-json-deserialize
    – joanis
    Aug 7, 2019 at 14:09
  • Possible duplicate of VB.net JSON Deserialize
    – joanis
    Aug 7, 2019 at 14:10
  • 1
    @video.baba Newtonsoft.Json and Json.Net are indeed the same thing. If you go to the Newtonsoft website you will see the product is actually called Json.Net. Aug 7, 2019 at 15:08

1 Answer 1

0

Your JSON is an array of arrays of Class1 objects, so you need to deserialize to that.

Dim data As Class1()() = JsonConvert.DeserializeObject(Of Class1()())(json)

You don't actually need the Rootobject class here.

Working demo: https://dotnetfiddle.net/1JuaYk

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.