Download from URI in model error
Other problem was solved, now I've this one xD. Trying to do the following:
and getting errors
102 Replies
can you explain a little bit more what you want to do?
I want to download from the url in
card.ImageUri.Small
and where is that defined? what type is it?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Okie doke I will try that instead. I was just going with things I found on the internet lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ye
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
why can't I access the values in the properties?
card.ImageUris.Small
what's the type of this? where is it defined, where does it come from?I just edited and it added errors
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
It's a string property in a model for Json. It's just a URL for the image
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I thought card was the instance
and imageuri was inside it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I get what it means lol I just don't understand how it happened
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
try new Uri() and pass that
I would rather understand my misunderstanding with the Card class first
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yep
It's long do you just want the relevant chunk? It's all at the top anyways
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
oof
oh for sure I just figure it's right at the top so ya know
haha
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
a class inside a class
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
👀
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i thought it worked like a directory kek
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
part of the deserialize magic was my assumption, yes
lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
there's no way json2csharp gave you that
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm just using what Json2CSharp gave me
can u share the json
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/BlazeBin - sibkytwzugmv
A tool for sharing your source code with the world!
Okie doke my next question is if
Deserialize
doesn't create an instance of ImageUris
how does it populate the properties?wait a moment
first things first
ya np
go put that json in json2chsarp again
alright
you should get something like this
Yeah taht's what I got
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/okay then why did you put a class inside a class?
OH YOU'RE RIGHT I DID DO THAT
fudge
i couldn't get it to work otherwise
i forget what error it gave, I can show you if you'd like
Root already knows there is a property of type
ImageUris
so it will go the Imageuris
class to get the other properties
per object
since you are deserializing to a list
every object (root) has one property named ImageUris
which is this:
alright, I understand what you're telling me here
the idea is that classes are singular
yeah I get this now lol
let me take that out and show you original error then
so you can rename Root to let's say Card
then put that class in one file
RelatedUris in another
and so on
all inside a folder
and they will all be related to each other
when you deserialize or serialize
you go for the top one
which is Card
which will start travelling down
right right thank you so much for that
let me see if it even still give the error
if it finds a ImageUris type it will go to that class and serialize/deserialize it
Huh the error is no longer there
I understand now though the way it's not nested but relational, and you start with the primary class in the relation
thank you very much
I'm going to look back up at what ToBeClone said before
the reason I made the download choice I did was googling "download file with httpclient" lol
yeah that's like another problem
unrelated to this one
just to make it visible here
Well you solved the riddle of my model problem
lol so it's no longer a problem xD
it now deserializes fine
actually we all helped, hate taking the credit
xd
and the download code does not give error anymore either, lets see if it works!
well i fixed the naming
folder empty xD
I've never tried this before so ya know maybe it's the problem
File.WriteAllBytes($@"C:\Users\samue\Desktop\MTGImages\{card.Name}", fileBytes);
interpolate literal string?i would go with the suggestion TeBeClone said
just get the stream
open a file stream
and copy the stream there
basically you get the stream, you enable I/O operations and then copy it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Was my next step tobe
tyvm
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
alright folks, i'll let you know if it works in 9 hours when I'm free again
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
and @Henkypenky tyvm for explaining the json bit, I had no idea what Iwas doing and now I have a small idea.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah ngl the naming of things confuses me a bunch lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i never know which side of what it's referring to
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
like
create
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
is it creating the thing that holds the stream, is it creating the file from the stream, is it creating the stream itself in its container, etc
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
for sure I'm sure if I read it it'd be clearer, I'm just saying on its face it's a bit confusing
lots of learning programming has come across that way to me lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Oh for sure man. I hope you get I'm speaking generally without specific reference to any instruction
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
okay
wait so use
using
?might be better to open the filestream once
since there will be multiple creations
instead of 1 per creation
yeah I was gonna ask that too
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
multiple images
it's a list
yeah
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nope lol
$@"C:\Users\samue\Desktop\MTGImages\{card.Name}.jpg"
idk if that works either lol
i was gonna google it eventuallyUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
🤣 Alright I have irl obligations to fulfill. I greatly appreciate the help as always and hope to talk with you again later tonight.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
homie I appreciate it lol. Drop whatever you think I should look at in here, I promise I will.
ya that makes sense
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
❤️
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
later buddy
I'll close in 9 hours when I get to try it again