Im trying to convert my List code lines to Dictionary since as i understand they are faster, and more easy to manage, like i can get its value with its key value rather than just index.
Thus, im trying to modify my json-deserializing code (which actually,Newtonsoft's), but i have no idea how can i convert raw json to dictionary with my own format.
Dictionary <string,Tag>
Tag class is my own class with member variables, contains tag informations. it doesnt includes functions for sure.
String should be Tag.Name, a string member variable.
//TODO: Fix "Hacky" solution to deserialized lines into Dictionary
//Which means : Raw Json -> Deserialized data -> List -> Dictionary is very hacky in my perspective
//Should be : Raw Json -> Deserialized data -> Dictionary, but i have no idea to convert directly like that
else if (filename.Contains(".json")) // very janky method to detect json file. dont depend on file extension - rather depend on actual file format.
{
string line = String.Join("", Lines);
List<Tag> lv_list = new List<Tag>();
Dictionary<string,Tag> lv_dict = new Dictionary<string, Tag>();
lv_list = JsonConvert.DeserializeObject<List<Tag>>(line);
gVar.Tags.AddRange(lv_list);
gVar.gTagCount += lv_list.Count();
for (int i = 0; i < lv_list.Count(); ++i)
{
gVar.Tags2.Add(lv_list[i].Name, lv_list[i]);
}
int lv_tagcount = 1;
for (int i = 0; i < gVar.gTagCount; ++i)
{
gVar.Tags[i].TagCount = lv_tagcount;
++lv_tagcount;
}