added getting all users from response

This commit is contained in:
Sem van der Hoeven
2020-09-16 13:48:31 +02:00
parent 359484baa3
commit 3307f57f36

View File

@@ -10,20 +10,23 @@ namespace RH_Engine
class JSONParser class JSONParser
{ {
/// <summary> /// <summary>
/// parses the given response from the server into strings /// returns all the users from the given response
/// </summary> /// </summary>
/// <param name="msg">the message gotten from the server, without the length prefix</param> /// <param name="msg">the message gotten from the server, without the length prefix</param>
/// <returns></returns> /// <returns></returns>
public static string[] Parse(string msg) public static PC[] GetUsers(string msg)
{ {
dynamic jsonData = JsonConvert.DeserializeObject(msg); dynamic jsonData = JsonConvert.DeserializeObject(msg);
Newtonsoft.Json.Linq.JArray data = jsonData.data; Newtonsoft.Json.Linq.JArray data = jsonData.data;
PC[] res = new PC[data.Count];
int counter = 0;
foreach (dynamic d in data) foreach (dynamic d in data)
{ {
Console.WriteLine(d.clientinfo.host); res[counter] = new PC(d.clientinfo.host, d.clientinfo.user);
counter++;
} }
return null; return res;
} }