C
C#2mo ago
Kushiwushi

Cannot implicitly convert int to string

C#
foreach (var kv in json["lines"]) // there might be a faster way to do this? looks like this algo is On^ NO ITS NOT
{
Dictionary<string, int> lyricMap = new Dictionary<string, int>();
string words = kv.words;
int timeList = kv.startTimeMs;
lyricMap.Add("words", timeList);
{
string wordMap = lyricMap["words"];
}
}
C#
foreach (var kv in json["lines"]) // there might be a faster way to do this? looks like this algo is On^ NO ITS NOT
{
Dictionary<string, int> lyricMap = new Dictionary<string, int>();
string words = kv.words;
int timeList = kv.startTimeMs;
lyricMap.Add("words", timeList);
{
string wordMap = lyricMap["words"];
}
}
I'm trying to assign a variable to the "words" in the hashmap but for some reason apparently its an integer?
5 Replies
Angius
Angius2mo ago
Where does this error happen? As a side note, the var kv in json["lines"] looks curious. Are you manually parsing some JSON file you have? Line by line? Or you could go offline the moment you ask the question, sure
Kushiwushi
KushiwushiOP2mo ago
Ig? On string wordMap = lyricMap["words"] ;
Angius
Angius2mo ago
Ah, well, makes sense it shows you this error LyricMap is a dictionary where keys are strings and values are ints If you get a value by the key... ...you get an int I mentioned that, because System.Text.Json namespace exists and lets you parse json to a nice and proper class
Kushiwushi
KushiwushiOP2mo ago
Wait im actually at school I'll just take this in later ya Okay I think I'll get it, I'll try to implement it another way Ty
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?