Created
August 19, 2014 12:56
-
-
Save oguna/e6e02fc2465dae118641 to your computer and use it in GitHub Desktop.
NDLのJsonデータをC#シリアライザでデシリアイズする
This file contains hidden or 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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Net; | |
| using System.Threading.Tasks; | |
| using System.Diagnostics; | |
| using System.Threading; | |
| using System.Runtime.Serialization; | |
| using System.Runtime.Serialization.Json; | |
| using System.Globalization; | |
| namespace CSharpTest | |
| { | |
| [DataContract] | |
| class NDLJsonData | |
| { | |
| [DataMember] | |
| public string link; | |
| [DataMember] | |
| public NDLJsonDataIdentifier identifier; | |
| [DataMember] | |
| public NDLJsonDataTitle[] title; | |
| [DataMember] | |
| public string[] volume; | |
| [DataMember] | |
| public NDLJsonDataTitle[] seriesTitle; | |
| [DataMember] | |
| public NDLJsonDataCreator[] creator; | |
| [DataMember] | |
| public NDLJsonDataCreator[] dc_creator; | |
| [DataMember] | |
| public NDLJsonDataPublisher[] publisher; | |
| [DataMember] | |
| public string[] date; | |
| [DataMember] | |
| public string[] issued; | |
| [DataMember] | |
| public NDLJsonDataSubject subject; | |
| [DataMember] | |
| public string price; | |
| [DataMember] | |
| public string[] extent; | |
| [DataMember] | |
| public string[] materialType; | |
| } | |
| [DataContract] | |
| class NDLJsonDataTitle | |
| { | |
| [DataMember] | |
| public string value; | |
| [DataMember] | |
| public string transcription; | |
| } | |
| [DataContract] | |
| class NDLJsonDataIdentifier | |
| { | |
| [DataMember] | |
| public string[] JPNO; | |
| [DataMember] | |
| public string[] ISBN; | |
| } | |
| [DataContract] | |
| class NDLJsonDataCreator | |
| { | |
| [DataMember] | |
| public string name; | |
| [DataMember] | |
| public string transcription; | |
| } | |
| [DataContract] | |
| class NDLJsonDataPublisher | |
| { | |
| [DataMember] | |
| public string name; | |
| [DataMember] | |
| public string location; | |
| } | |
| [DataContract] | |
| class NDLJsonDataSubject | |
| { | |
| [DataMember] | |
| public string[] NDC9; | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var url = "http://iss.ndl.go.jp/books/R100000002-I000003057246-00.json"; | |
| var req = WebRequest.CreateHttp(url); | |
| var stream = req.GetResponse().GetResponseStream(); | |
| var serializer = new DataContractJsonSerializer(typeof(NDLJsonData)); | |
| var data = (NDLJsonData)serializer.ReadObject(stream); | |
| var list = new List<KeyValuePair<string, string>>(); | |
| list.Add(new KeyValuePair<string, string>("タイトル", data.title[0].value)); | |
| list.Add(new KeyValuePair<string, string>("著者", data.dc_creator[0].name)); | |
| list.Add(new KeyValuePair<string, string>("著者標目", data.creator[0].name)); | |
| list.Add(new KeyValuePair<string, string>("シリーズ名", data.seriesTitle[0].value)); | |
| list.Add(new KeyValuePair<string, string>("出版社", data.publisher[0].name)); | |
| list.Add(new KeyValuePair<string, string>("出版年", data.date[0])); | |
| list.Add(new KeyValuePair<string, string>("巻次", data.volume[0])); | |
| Console.WriteLine(data.title[0].value+" "+data.volume[0]); | |
| Console.WriteLine("----------------------------------------"); | |
| foreach(var i in list) | |
| { | |
| Console.WriteLine(i.Key+" : "+i.Value); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment