C
C#6h 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?
4 Replies
Angius
Angius6h 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
KushiwushiOP4h ago
Ig? On string wordMap = lyricMap["words"] ;
Angius
Angius4h 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
KushiwushiOP3h 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

Did you find this page helpful?