json parser stuff

This commit is contained in:
Sem van der Hoeven
2020-09-16 12:14:04 +02:00
parent b0dc258455
commit 5699f8678e
2 changed files with 14 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -15,7 +16,15 @@ namespace RH_Engine
/// <returns></returns> /// <returns></returns>
public static string[] Parse(string msg) public static string[] Parse(string msg)
{ {
dynamic jsonData = JsonConvert.DeserializeObject(msg);
Newtonsoft.Json.Linq.JArray data = jsonData.data;
foreach (dynamic d in data)
{
Console.WriteLine(d.clientinfo.host);
}
return null; return null;
} }

View File

@@ -12,7 +12,8 @@ namespace RH_Engine
TcpClient client = new TcpClient("145.48.6.10", 6666); TcpClient client = new TcpClient("145.48.6.10", 6666);
WriteTextMessage(client, "{\r\n\"id\" : \"session/list\"\r\n}"); WriteTextMessage(client, "{\r\n\"id\" : \"session/list\"\r\n}");
ReadPrefMessage(client.GetStream()); string result = ReadPrefMessage(client.GetStream());
JSONParser.Parse(result);
} }
@@ -42,10 +43,10 @@ namespace RH_Engine
int read = stream.Read(buffer, totalRead, buffer.Length - totalRead); int read = stream.Read(buffer, totalRead, buffer.Length - totalRead);
totalRead += read; totalRead += read;
Console.WriteLine("ReadMessage: " + read); //Console.WriteLine("ReadMessage: " + read);
Console.WriteLine(Encoding.UTF8.GetString(buffer)); //Console.WriteLine(Encoding.UTF8.GetString(buffer));
return Encoding.ASCII.GetString(buffer, 0, totalRead); return Encoding.UTF8.GetString(buffer);
} }
} }
} }