JSON Parsing to TreeView
Hello. I'm still banging my head on my desk the past 2 days trying to read a .json file which has a "table" root, into a TreeView. You'd think it would be easy for a dumbass but nope. Please help 😦
I tried ChatGPT, I tried Google, MS Learn, etc and I am a loser somehow.
The example CharacterMapping.json file:
The source is here (FUCK GITHUB it keeps breaking)
32 Replies
Okay so what exactly is the problem with this Json and how it relates to GitHub
Ok, #1 skip github
please read the post
I just need an answer about it 😦
code is in the .zip, you cna keep it, its not copyrighted
its just a winform with 1 class and 1 model
I've read the post . You have not described much.
There's a table array in the Json and each object has a few properties. So what's the problem in it
I want them in a treeview
so like this:
Game modding sucks and the 1 community I was in, is a toxic dump so so trying to make things myself
Also, posting a zip or even txt file of your code is frowned upon. Use $paste instead please.
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
hold pls
And where do you want to display that information in this structure?
https://paste.mod.gg/ypsrxkvwbqzi/0
JsonParser class (diff namespace)
BlazeBin - ypsrxkvwbqzi
A tool for sharing your source code with the world!
In your WinForms app ?
MainApp form code behind
Yes, in the TreeView
hell, a listbox if i need to if its not possible lol
The issue probably isn't even the TreeView, it's my parsing
I always did suck at structures in json
Well I'd just fetch and deserialize the Json to a List in the code behind and would show them in the form of the code behind and would design accordingly or would use an existing control
(Why aren't you using WPF? Because this is TESTING, not gonna code 500 lines oof xaml to put a button and treeview on a form)
I'm the designer too so i guess ill do it
its just me, no team and no job
Try this
i modified it to include List<modenamehere>
but what am i returning?
Lemme eat lunch first
I wish I had my old code from when I did a inventory app, same idea for models back 10 years ago :/
np take your time , i appreciate the help. its 5am for me lol
@/dev/null/CoreDream So listen.
The algorithm that I propose is as follows:
1. First of all in your code behind get all the Json in a string from your Json file.
2. Now deserialize the obtained json to a List of the object. Where object should be extractly structured like the objects in the Json. Like same properties etc. Like create a model class.
3. Once you have successfully deserialized the Json to the list now you have the data you need. So you can look for some TreeView controls or any control tha can help you design it the way you want, so you would just bind the obtained data to those controls.
For the step 3 , you can seek further expertise in #gui
ty
Also I've just checked that there already exists a TreeView control in the WinForms. So after deserializing The data you just need to bind the data with that control and you are done
no problem
JsonSerializer.Deserialize
can also take a stream btw, so u could simply open a file stream and pass that, especially for a big file this will require a lot less memoryif only it was that easy in winforms, sadly u have to make your own method to populate teh treeview
oh! I looked at some examples but Idk how binding works (yk am a webview guy)
you suggested him now u figure it out!
:catpout:
:pepeawooga:
ty
yeah fuck winforms, i think wpf is better afterall XD
if ur going wpf then do take the time to learn xaml its important and will help u along your journey
how the controls work, templates, bindings etc
for the simple use case like that I won't do such migration, as apparently it's kind of a modding program
I mean its up to him to decide what he wants to use.
if he feels winforms is not it... then that's that...
Winfroms can be easy to get up and going but mvvm with winform is not really that simple as it is with XAML based frameworks because not all controls in winforms allow for binding data like datagrid or listbox etc or accept a datasource
alright, the last part is bad. The way it's popular it should've supported proper binding at least . Not sure what else they do
it does in some controls not everything and it will be improved on .net 9