WPF read and write to Json [Answered]
The title says it all, I don't know how to read and write to Json properly. I tried some things but they don't seem to work
i have looked for tutorials guides everywhere, but nothing worked for me. I must be doing something wrong
30 Replies
what does the json look like, and what does your
persondata
class look likeMy class is just this
My Json is empty right now
i mean if the json is empty, what data do you expect to deserialize into the list?
<a:aPES4_WeirdStare:827518462745772084>
Whops
I forgot, that I actually had to have something in my Json. Thanks xd
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Be wary of mixing newtonsoft with System.Text.Json thou
can nsj/stj work with init props?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
also your code won't work will it
this is probably what you meant
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Wow thanks everyone, I had no idea about the PascalCase and camelCase
JsonConvert.DeserializeObject is from Newtonsoft Package so use [JsonProperty] instead
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
newtonsoft isnt case sensitive i think
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
stj has JsonConvert?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i've only ever used JsonSerializer
No
the attribute JsonPropertyName is totally useless there
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
and this
JsonSerializer.Deserialize<
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
tebeco#0205
REPL Result: Success
Result: ValueTuple<PersonData, PersonData>
Compile: 639.697ms | Execution: 93.213ms | React with ❌ to remove this embed.
iirc, stj is case sensitive, but u can pass an option settings to make it case insensitive
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Wow thanks everyone, I appreciate it a lot! It actually works. I can write to my Json. I don't know if it reads it, but I can suddenly write to it, I have not checked if it reads yet. Thanks! 👍
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ah okay, that's fine. I don't have a preference, as long as I learn a way to read and write to Json. Doesn't matter which way to me. I appreciate all the help
✅ This post has been marked as answered!