The data contained in your file are in JSON format. JSON is quite simple to read, if formatted correctly. If I reformat your input the structure becomes clearer:
{
"players": [
{
"i": 11,
"p": 0,
"a": 3186,
"n": "IanHx",
"f": 1,
"ps": 0,
"pd": 0,
"bc": 0
},
{
"i": 12,
"p": 0,
"a": 115,
"n": "LoZtamnik",
"f": 1,
"ps": 0,
"pd": 0,
"bc": 0
},
{
"i": 58,
"p": 0,
"a": 156,
"n": "Mr701",
"f": 2,
"ps": 0,
"pd": 0,
"bc": 0
},
{
"i": 59,
"p": 0,
"a": 156,
"n": "B0NE4",
"f": 2,
"ps": 0,
"pd": 0,
"bc": 0
},
{
"i": 64,
"p": 0,
"a": 324,
"n": "5teveJ",
"f": 1,
"ps": 0,
"pd": 0,
"bc": 0
}
]
}
In JSON, anything enclosed in [ ] denotes a collection and anything enclosed in { } denotes an object. So, you can see that you have a collection called players which contains 5 objects (since there are 5 pairs of { } within players [ ]) with 8 properties each. If you think of these in C# terms, you would have a class called Player with those 8 properties, and a List<Player> to hold each Player instance. You could then take the JSON data and deserialize them into their C# counterparts so you can manipulate them as you see fit, as Dave Bish has pointed out in his answer.
There's a very easy way to create the C# classes from your JSON data automatically:
- Create a new class in your project, name it however you want and
clear all of it's content
- Copy the JSON data (either from my example or yours)
- Go back to the class and click
Edit -> Paste Special -> Paste JSON As Classes
Voila. Visual Studio's got your back. You should now see something along these lines:
public class Rootobject
{
public Player[] players { get; set; }
}
public class Player
{
public int i { get; set; }
public int p { get; set; }
public int a { get; set; }
public string n { get; set; }
public int f { get; set; }
public int ps { get; set; }
public int pd { get; set; }
public int bc { get; set; }
}
You can then do whatever suits your scenario best, e.g. add the System.Collections.Generic namespace so you can make Player[] a List<Player> instead so on.
Now, to manipulate the JSON data and deserialize them into the C# class we've just created, you can use the excellent Json.NET library. To add it, right click your application from the solution explorer and click "Manage NuGet Packages...". Type "Json.NET" in the search box and install it.
Once you have that in place, add the Newtonsoft.Json namespace and you're good to go. You can now use Json.NET's DeserializeObject<T>() method to deserialize the JSON data into the C# classes we've created:
//i've hardcoded the JSON data here, obviously you would extract them from your file
var jsonData = @"{""players"":[{""i"":11,""p"":0,""a"":3186,""n"":""IanHx"",""f"":1,""ps"":0,""pd"":0,""bc"":0},{""i"":12,""p"":0,""a"":115,""n"":""LoZtamnik"",""f"":1,""ps"":0,""pd"":0,""bc"":0},{""i"":58,""p"":0,""a"":156,""n"":""Mr701"",""f"":2,""ps"":0,""pd"":0,""bc"":0},{""i"":59,""p"":0,""a"":156,""n"":""B0NE4"",""f"":2,""ps"":0,""pd"":0,""bc"":0},{""i"":64,""p"":0,""a"":324,""n"":""5teveJ"",""f"":1,""ps"":0,""pd"":0,""bc"":0}]}";
//deserialize the JSON into the C# class we created and store it in myPlayerData
var myPlayerData = JsonConvert.DeserializeObject<Rootobject>(jsonData);
//you can now do stuff such as..
foreach(Player player in myPlayerData.players)
{
MessageBox.Show(string.Format("Player {0} has an i of {1} and an a of {2}", player.n, player.i, player.a));
}