Skip to content

Instantly share code, notes, and snippets.

@renaudbedard
Created September 13, 2012 15:23
Show Gist options
  • Save renaudbedard/3715057 to your computer and use it in GitHub Desktop.
Save renaudbedard/3715057 to your computer and use it in GitHub Desktop.
JsonFx WFH
// ...
static JsonWriter jsonWriter;
static JsonReader jsonReader;
ReadResponse readResponse;
class ReadResponse
{
public string Message;
public ServerInfo[] Servers;
}
class ServerInfo
{
public string Ip;
public int Players;
public string Map;
public int Id;
public object Packed
{
get { return new { ip = Ip, players = Players, map = Map }; }
}
public override string ToString()
{
return jsonWriter.Write(this);
}
}
void Start()
{
jsonWriter = new JsonWriter(new DataWriterSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase)));
jsonReader = new JsonReader(new DataReaderSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.CamelCase)));
}
void QueryServerList()
{
using (var client = new WebClient())
{
var response = client.DownloadString("http://api.xxiivv.com/?key=7377&cmd=read");
Debug.Log("Got server list : " + response);
try
{
var data = jsonReader.Read<ReadResponse>(response);
Debug.Log("Message : " + data.Message);
Debug.Log(data.Servers.Length + " servers : ");
foreach (var s in data.Servers)
Debug.Log(s);
readResponse = data;
}
catch (Exception ex)
{
Debug.Log(ex.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment