JSON string to dictonary

I have a JSON string which goes by

"players":"PLAYER1:PASSWORD1;PLAYER2:PASSWORD2"

Anyway to convert this in to dictionary like
Player1 → PASSWORD1
Player2 —>PASSWORD2

and so on

sure, split on ‘;’ to get the pairs, split those pairs on ‘:’ to get your key and value. Fill the array accordingly.

1 Like

or just de-serialize which might be to something like:

Dictionary<string,string> players;

not even sure you have to put it into a separate class even to do this.

But you could also do something like

class PlayerList
{
  List<Player> Players;
}

class Player
{
  public string Name;
  public string Password;
}

… might change your JSON to be something like:

{
“players”:[{
“name”:“player1”,
“password”:“hello”
},{
“name”:“player2”,
“password”:“hello2”
}]
}