I Have the following text from a file:
{"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}],[.......
What i am trying to do is parse the text, to end up with a array for each bit of data between {...}
so final result would look like:
i=11
p=0
a=3186
n=IanHx
f=1
ps=0
pd=0
bc=0
then i can store these in a database
so far i have something like this:
string contents = System.IO.File.ReadAllText("local text file"); //load string contents with text file
Regex regex1 = new Regex(""players":\[(?<players>.*)\]"); //find the players section "players":[.......]
Match match1 = regex1.Match(contents); //load match1
Regex regex2 = new Regex("{(?<player>([^}]*))}"); // then break down each player {....}
MatchCollection match2 = regex2.Matches(match1.Groups["players"].Value); //load match2 with each player
then i get stuck trying to split the match string[] somehow and looking at it may be overcomplicating it?
any pointer to an easier solution to the data parsing
Thanks
See Question&Answers more detail:
os