程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> csharp: json to csharp,csharpjsonto

csharp: json to csharp,csharpjsonto

編輯:C#入門知識

csharp: json to csharp,csharpjsonto


 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");
                //驗證服務器證書回調方法 
                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);
            // 設置當前流的位置為流的開始
            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)
        {
            // 把 Stream 轉換成 byte[]
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            // 設置當前流的位置為流的開始
            stream.Seek(0, SeekOrigin.Begin);
            // 把 byte[] 寫入文件
            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)
        {
            // 打開文件
            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            // 讀取文件的 byte[]
            byte[] bytes = new byte[fileStream.Length];
            fileStream.Read(bytes, 0, bytes.Length);
            fileStream.Close();
            // 把 byte[] 轉換成 Stream
            Stream stream = new MemoryStream(bytes);
            return stream;
        }

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved