I can't JSON to List ;_; [Answered]
That's my error
Here's my attempt to just call and dump it into a List.
100 Replies
I looked at the JSON returned and it starts like this
{"cards":[{"name":"Ancestor's**
so I see where my issue is, but I don't know how to address it.
a <List<Card>
is not the same as a {"cards": arrayOfCards
so I understand I should make a class for the "cards"
in the json, with my existing Cards
class inside of it. I'm going to try that.Did you create the json by hand?
No it's return from the URL above
https://api.magicthegathering.io/v1/cards/
This returns 100 cards as default
and the opening
{"cards":[{"name":"Ancestor's
here indicates there is an object above the actual card when returning multiple correct? I don't know what it looks like when returning 1 card alone
that was meant to be a question. sorryAre you using Visual Studio?
yepper
This might help you:
what do i click on?
That's on the Edit menu
lol I'm misunderstanding.
yeah I just gotta copy the return first.
still get the error using autogenerated content
sec
Did you try deserializing to RootObject?
No, just RootObject
Not List
oh lmao
okay
okay that worked. I understand a bit now.
I wasn't adding
Card
as array in my previous class
second question, if it returns one object, this form is still generally valid, or is it implementation dependentNot sure what you mean
the fact that the return structure is a list of cards in this case
Totally depends on what was serialized
if it's one card returned it'd probably still be
{"cards": oneCardInArray
oh alrightBTW you can change Card[] to List<Card> and it should still work just fine.
yeah thanks for that too
so when the json has an array built in I can't use the
Deserialize<List<Object>
that is what was tripping me up because EVERY tutorial on it I found was using that the deserialize multiple objects returned b ythe jsonI don't actually work with JSON that much but I don't think you can choose to deserialize a subset of the data. I think other formats like protobuf actually support that but I'm not aware that JSON does.
well not to to a portion, just the way you tell it it's a list
or array
but either way I understand a bit more, and thank you very much for that.
✅ This post has been marked as answered!
You can serialize a List<Card> yourself to see what that looks like in JSON. The root element is a JSON array in that case.
It looks like this (I removed all properties except Name for brevity)
Yeah I get that bud
Now you could take that and deserialize that to a List<Card>. But that's not the format that the web site is giving you.
so what's the point of deserialize<list<object>>
right that's not the format
yeah I was just approaching it the wrong way because I didn't look at the data
The point is that you would use that for data that is formatted like the example I gave above.
Yeah that's how the bulk data is formatted
I tried that first which is why I was on this path lol
couldn't get that sorted either xD.
well I may just comment here for you when I try the bulk data again.
thank you very much for the help.
yes the return from the api was the {"cards": {...} thing
I couldn't figure out how to send specific delimiters to it, but that's not really a C# question lol
lol why is this a bruh moment? I have 0 experience with this jsyk xD
I did a specific card via
\card\cardIdNumber
instead of a query to get a single card and it returned JSON in the same format. Unless you meant something else.
I lied actually. It is inconsistent. lol.
I figured it'd automatically wrap it in an array so it could be deserialized the same way every time.
Hey one more question if you don't mind. There's SDK available for this API and .net but I'm avoiding to learn more about .net and not their SDK. Does that make sense? Or should I just use the SDK and this hardship is a bit of a waste of time?@rtreit probably loves this question...
My twin brother.
He doesn't like SDKs
lmaooo
I figured it would be a valuable learning experience. Was I wrong?
Using the raw web calls instead of the SDK is absolutely a valuable learning experience
I'll probably take up the SDK at some point to make learning other things easier, but for now it seemed like a good choice.
most awesome. Thanks for the reassurance bud.
If you have suggestion for what specifically to git gud with in this regard I'm all ears xD
I was just gonna pick things that looked relevant from the docs and try implementing whatever
^this
Just keep doing what you're doing I think
aight.
Thanks again.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I only used System.Text.Json for this experiment
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh I didn't know that was a thing thanks man
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
could you edit in the code I did?
so i can see easier to compare?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
do you mean don't pass the response to a string first?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
alright will do
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm not sure what you're saying so 🙂
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
lmao
i'm gonna try and do that in a bit thanks again
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah that makes a ton of sense
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
so i can deserialize the object that gets the json directly
i didn't know that
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
tbh i didn't even know what that object is because i always see it as
var
isn't it just a string anyways?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I really have no idea what @tebeco is talking about but as someone who doesn't know json I assume he has some point
yeah for sure. I'm just learning it so i didn't bother doing the extras
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm aware of this but have no idea how it applies to the code examples in this thread
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hey can you write out what you mean for me?
here's the original method
just so i can see what you're saying
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh crap lmao
that's uh, a huge improvement
What does that have to do with utf8?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it's a lot less data getting created and dumped for no reason
System.Text.Json doesn't care? I'm missing something
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
what does GetJsonAsync come from?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nope. I saw some stuff about blazor
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
but I'm not using anything blazor
googling the command
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I guess I need to see a benchmark
well json.http isn't it xD
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
That wasn't a joke <:PES_SadGe:814280618959568896>
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm supposed to be doing shoulder shrugs right now 👀
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
oh no i was just shitposting lol. I'm sitting her etrying to get this package to work instead of finishing workout
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Just do the simplest thing possible and don't worry about micro-optimization
i added from package manager but still not working
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
not recognizing the command
saved and reopened 1 sec
i installed from package manager and have using
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
is it because client is HttpClient?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
LMAO no error now 1 sec
lmao because I read
getfromjsonasyn
when googling and didn't catch it
derp
Hot diggity that's cool man
thanks a ton for telling me about that package
what's BCL
Oh. I had to add it 🤷🏻♂️
what that means, idk. lmao.
yeah wasn't available to HttpClient until added
unless i did something wrong which is always a possibility xDUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
✅ This post has been marked as answered!