Created
September 13, 2012 15:23
-
-
Save renaudbedard/3715057 to your computer and use it in GitHub Desktop.
JsonFx WFH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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