[chronojump] Adds example file to get a JSON from the server and parse the output.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Adds example file to get a JSON from the server and parse the output.
- Date: Wed, 28 Jan 2015 23:33:44 +0000 (UTC)
commit 693830648adcbe676ecffc5a871f92260407f6c4
Author: Carles Pina i Estany <carles pina cat>
Date: Wed Jan 28 23:32:56 2015 +0000
Adds example file to get a JSON from the server and parse the output.
testing-stuff/json_get.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/testing-stuff/json_get.cs b/testing-stuff/json_get.cs
new file mode 100644
index 0000000..d0d286b
--- /dev/null
+++ b/testing-stuff/json_get.cs
@@ -0,0 +1,49 @@
+//Carles Pina
+//compile: mcs json_post.cs /reference:System.Json.dll
+
+using System;
+using System.Net;
+using System.Web;
+using System.IO;
+using System.Json;
+
+public class JsonTest
+{
+ static public void Main()
+ {
+ // Create a request using a URL that can receive a GET.
+ WebRequest request = WebRequest.Create ("http://api.chronojump.org:8080/version");
+
+ // Set the Method property of the request to POST.
+ request.Method = "GET";
+
+ // Get the response.
+ WebResponse response = request.GetResponse ();
+
+ // Display the status.
+ Console.WriteLine ("StatusDescription:" + ((HttpWebResponse)response).StatusDescription);
+
+ Stream dataStream;
+
+ // Get the stream containing content returned by the server.
+ dataStream = response.GetResponseStream ();
+
+ // Open the stream using a StreamReader for easy access.
+ StreamReader reader = new StreamReader (dataStream);
+
+ // Read the content.
+ string responseFromServer = reader.ReadToEnd ();
+
+ // Display the content.
+ Console.WriteLine (responseFromServer);
+
+ // Clean up the streams.
+ reader.Close ();
+ dataStream.Close ();
+ response.Close ();
+
+ JsonValue result = JsonValue.Parse(responseFromServer);
+ string stable_version = result["stable"];
+ Console.WriteLine("stable version is: "+ stable_version);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]