Csharp: json to csharp,

Source: Internet
Author: User

Csharp: json to csharp,

Http://json2csharp.com/
Http://jsonclassgenerator.codeplex.com/
Http://jsonutils.com/
Https://github.com/bladefist/JsonUtils ///

Http://json.codeplex.com/

Https://www.mssqltips.com/sqlservertip/3449/making-sql-server-metadata-queries-easier-with-these-new-views/

Http://www.sqlteam.com/article/using-metadata

 

  public class Rating    {        public int max { get; set; }        public int numRaters { get; set; }        public string average { get; set; }        public int min { get; set; }    }    public class Tag    {        public int count { get; set; }        public string name { get; set; }        public string title { get; set; }    }    public class Images    {        public string small { get; set; }        public string large { get; set; }        public string medium { get; set; }    }    public class Series    {        public string id { get; set; }        public string title { get; set; }    }    public class Example    {        public Rating rating { get; set; }        public string subtitle { get; set; }        public IList<string> author { get; set; }        public string pubdate { get; set; }        public IList<Tag> tags { get; set; }        public string origin_title { get; set; }        public string image { get; set; }        public string binding { get; set; }        public IList<string> translator { get; set; }        public string catalog { get; set; }        public string pages { get; set; }        public Images images { get; set; }        public string alt { get; set; }        public string id { get; set; }        public string publisher { get; set; }        public string isbn10 { get; set; }        public string isbn13 { get; set; }        public string title { get; set; }        public string url { get; set; }        public string alt_title { get; set; }        public string author_intro { get; set; }        public string summary { get; set; }        public Series series { get; set; }        public string price { get; set; }    }

  

WebClient client = new WebClient (); client. credentials = CredentialCache. defaultCredentials; client. encoding = Encoding. UTF8; strjson = client. downloadString (URL); // MessageBox. show (strjson); // string reply = client. uploadString (URL, data); // var jsonlist = JsonConvert. deserializeObject <List <DoubanBoookInfo> (strjson); BookExample book = new BookExample (); book = JsonConvert. deserializeObject <BookExample> (strjson); // MessageBox. show (book. title); this. textBoxprice. text = book. price; this. textBoxpubdate. text = book. pubdate; this. textBoxtitle. text = book. title; this. textBoxImage. text = book. image; Images imgurl = book. images; Encoding encoding = Encoding. getEncoding ("UTF-8"); // verify the server certificate callback method ServicePointManager. serverCertificateValidationCallback = new System. net. security. remoteCertificateValidationCallback (CheckValidationResult); // 1 HttpWebRequest request = (HttpWebRequest) WebRequest. create (book. image); request. method = "GET"; HttpWebResponse response = (HttpWebResponse) request. getResponse (); // String ver = response. protocolVersion. toString (); Stream stream = response. getResponseStream (); List <byte> list = new List <byte> (); while (true) {int data = stream. readByte (); if (data =-1) break; else {byte B = (byte) data; list. add (B) ;}} byte [] photocontent = list. toArray (); Image photo = BytesToImage (photocontent); this. pictureBox1.Image = photo; // 2 HttpWebRequest objRequest = (HttpWebRequest) WebRequest. create (imgurl. large); objRequest. method = "GET"; HttpWebResponse objResponse = (HttpWebResponse) objRequest. getResponse (); Stream streambs = objResponse. getResponseStream (); System. drawing. image img = System. drawing. image. fromStream (streambs); this. pictureBox2.Image = img;

  

/// <Summary> ///// </summary> /// <param name = "bytes"> </param> /// <returns> </returns> public Image BytesToImage (byte [] bytes) {MemoryStream ms = new MemoryStream (bytes); ms. position = 0; Image img = Image. fromStream (ms); ms. close (); return img ;} /// <summary> ///// </summary> /// <param name = "stream"> </param> /// <returns> </returns> public byte [] StreamToBytes (Stream stream) {byte [] bytes = new byte [stream. length]; stream. read (bytes, 0, bytes. length); // set the current stream position to the starting stream of the stream. seek (0, SeekOrigin. begin); return bytes ;} /// <summary> ///// </summary> /// <param name = "bytes"> </param> /// <returns> </returns> public Stream BytesToStream (byte [] bytes) {Stream stream = new MemoryStream (bytes); return stream ;} /// <summary> ///// </summary> /// <param name = "fileName"> </param> /// <returns> </returns> private byte [] SetImageToByteArray (string fileName) {FileStream fs = null; try {fs = new FileStream (fileName, FileMode. open, System. IO. fileAccess. read, FileShare. readWrite); Bitmap bt = new Bitmap (fs); int streamLength = (int) fs. length; byte [] image = new byte [streamLength]; fs. read (image, 0, streamLength); return image;} catch (Exception) {throw;} finally {fs. close ();}} /// <summary> //// </summary> /// <param name = "stream"> </param> /// <param name = "fileName "> </param> public void StreamToFile (Stream stream, string fileName) {// convert Stream to byte [] byte [] bytes = new byte [stream. length]; stream. read (bytes, 0, bytes. length); // set the current stream position to the starting stream of the stream. seek (0, SeekOrigin. begin); // write byte [] to the file FileStream fs = new FileStream (fileName, FileMode. create); BinaryWriter bw = new BinaryWriter (fs); bw. write (bytes); bw. close (); fs. close ();} /// <summary> ///// </summary> /// <param name = "fileName"> </param> /// <returns> </returns> public Stream FileToStream (string fileName) {// open the file FileStream fileStream = new FileStream (fileName, FileMode. open, FileAccess. read, FileShare. read); // Read the byte [] byte [] bytes = new byte [fileStream. length]; fileStream. read (bytes, 0, bytes. length); fileStream. close (); // convert byte [] to Stream stream = new MemoryStream (bytes); return stream ;}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.