Issue with JSON serialization of a nested dictionary
I can update the allMediaSource nested dictionary fine and vs2022 debug shows it has new values, but when I serialize the nested dictionary, it has original values
18 Replies
debug showing updated allMediaSources, see circled item
this is correct
next code line serializes to a string, which has wrong info
Imagesource should be Title
in the newJsonString
okay when you create nestedDictionary here:
You create a new variable that points to
allMediaSources[scraper]
however, reassigning this variable does not change the value of allMediaSources[scraper]
it just assigns a new value to that varible. IE that variable now points to something else.
if you want to update allMediaSources[scraper]
you need to assign the new value to allMediaSources[scraper]
.they don't reassign that variable
hmm... did I missread?
where do you see them doing that
sorry I missread this line:
nestedDictionary[system] = mediaSources;
so in the new string "mastersystem":{"ImageSource":"Screenshot" is wrong
but it's correct in the dictionary
should be Title, not ScreenShot
seems weird.... I dunno, I'm no expert lol
maybe I should try newtonsoft.json and see if the behavior continues or not... maybe it's a cache issue of some sorts?
i wanted to avoid as much third party in my program as I could
no, there's just more going on in your code than you sent, I think
or the serialization is using the wrong reference, but I don't see that in my code
wait, no it doesnt
it's correct
up at the top
underlined line
you just have several different mastersystem's in the json
yes, each is under a different scraper
so the json is correct after all
so easy to get confused with nesting
my issue must be then how I am retrieving it later
you might find it helpful to create some simple classes to help manage this.
anyways, this code adds the
mediaSource
like you originally asked (not really changed from the original). https://dotnetfiddle.net/mTM9KjC# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
also the
[]
syntax to create empty dictionaries (even nested ones)thank you.. taking a break to rest my brain
I finally found the issue in my code, an index for a combobox was not being created correctly
i used linq to fix it... love linq