C
Join ServerC#
help
❔ Adding logic into a JSON serializer
PPdawg11/28/2022
Hey everyone! I need to add logic into a json object, but I can't add any code in there or else it'll break. Here is what I mean: If I have a
Dictionary
named Icons, I need to say foreach item selected from the filepicker, create a new keypair in the Dictionary
. Basically, the user selects a few .png files, the code needs to copy them to a folder and add those names to the dictionary. Here is my current code that is a static dictionary:private async void SerializeJSON()
{
var model = new ObjectModel
{
ManifestVersion = 1,
Name = TileTitle,
Description = DescriptionTile,
Version = 1,
VersionString = "1",
Author = AuthorTile,
Organization = OrgTile,
ContactEmail = TileEmail,
TileIcon = new Dictionary<int, string>
{
[46] = "icons/tileIcon.png"
},
BadgeIcon = new Dictionary<int, string>
{
[24] = "icons/badgeIcon.png"
},
Icons = new Dictionary<string, string>
{
["iconTest"] = "newIcon1.png" // I need to add more items here when needed, based on what is pulled from the filepicker
},
};
}
SSunder11/29/2022
you could create the Dictionary before that and use that dictionary for the Icons or you can add a loop after assigning the Dictionary and add items to
model.Icons
PPdawg11/29/2022
Oh okay, so then just assign the icons object to the dictionary?
PPdawg11/29/2022
But create the dictionary and add content pre serialization
SSunder11/29/2022
Yes
SSunder11/29/2022
Adding content after it being serialized is quite hard
SSunder11/29/2022
Youll have to deserialize it, add it and then serialize it again
SSunder11/29/2022
So if you can do it before serializing it would be the best
PPdawg11/29/2022
Thanks! Will try it out.
PPdawg11/29/2022
@Sunder Thanks so much! Works flawlessly 🙂
AAccord11/30/2022
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.