Skip to content

Instantly share code, notes, and snippets.

@CH3COOH
Created September 20, 2014 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CH3COOH/4b2b3adac840eed9de78 to your computer and use it in GitHub Desktop.
Save CH3COOH/4b2b3adac840eed9de78 to your computer and use it in GitHub Desktop.
東京メトロ オープンデータ API の遅延情報取得例
static void Hoge()
{
var endPoint = "https://";
var parm = new Dictionary<string, string>();
parm["rdf:type"] = "odpt:TrainInformation";
parm["acl:consumerKey"] = アクセスキー";
var url = string.Format("{0}?{1}", endPoint,
string.Join("&", parm.Select(p => string.Format("{0}={1}", p.Key, p.Value))));
var client = new WebClient();
client.Encoding = Encoding.UTF8;
var jsondl = client.DownloadString(url);
JsonConvert.DeserializeObject<Class1[]>(jsondl)
.ToList()
.ForEach(item =>
{
Debug.WriteLine("{0} /{1}", item.railway, item.context);
});
}
public class Class1
{
[JsonProperty("@context")]
public string context { get; set; }
[JsonProperty("@id")]
public string id { get; set; }
[JsonProperty("dc:date")]
public DateTime date { get; set; }
[JsonProperty("dct:valid")]
public DateTime tvalid { get; set; }
[JsonProperty("odpt:operator")]
public string Operator { get; set; }
[JsonProperty("odpt:railway")]
public string railway { get; set; }
[JsonProperty("odpt:timeOfOrigin")]
public DateTime timeOfOrigin { get; set; }
[JsonProperty("odpt:trainInformationText")]
public string trainInformationText { get; set; }
[JsonProperty("@type")]
public string type { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment