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");
                //验证服务器证书回调方法
                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;
        }

  

时间: 2024-10-12 09:57:40

csharp: json to csharp的相关文章

Excel转Json,Json转CSharp

一份给策划最好的礼物!就是:Excel2Json2CSharp 策划配置Excel,动不动就要改数值啊,增加字段啊.程序这边对应的解析类就得改动啊.整一个麻烦了得!所以我就整理了这个Excel2Json2CSharp工具,让策划自个玩去了吧~!为了Windows和Mac都能使用(亲测都可用),我没有用wpf或者winform来做.还是以Unity插件形式提供. Excel2Json2CSharp功能 :1.把指定路径下的所有excel文件全部生成Json文件2.把指定路径下的所有Json文件全部

Java和CSharp的类继承的执行过程的差异

Java和CSharp的类继承的执行过程的差异: Java的执行过程:子类先初始化父类的成员→初始化父类的构造函数→返回子类执行初始化子类的成员→初始化子类构造函数. CSharp的执行过程:子类先初始化子类的成员→初始化父类的成员→初始化父类的构造函数→初始化子类的构造函数. 假设:A类继承自B类. Java的执行过程:A类先初始化B类的成员→初始化B类的构造函数→ 初始化A类的成员→初始化A类的构造函数. CSharp的执行过程:A类先初始化A类的成员→初始化B类的成员→初始化B类的构函数→

C# Newtonsoft.Json 解析多嵌套json 进行反序列化

[javascript] view plain copy [ { "orderNo": "3213123123123", "time": "2016-09-09 12:23:33", "orderStatus": "1", "freeShipping": true, "fullCut": 20, "originalCost": 

ASP.NET中XML转JSON的方法

原文:ASP.NET中XML转JSON的方法 许多应用程序都将数据存储为XML的格式,而且会将数据以JSON的格式发送到客户端以做进一步处理.要实现这一点,它们必须将XML格式转换为JSON格式. XML转JSON代码 [csharp] view plaincopy private static string XmlToJSON(XmlDocument xmlDoc) { StringBuilder sbJSON = new StringBuilder(); sbJSON.Append("{ &

C# Json简单处理

最近练习写的项目有涉及到json部分,其实明明可以url直接传参,我偏偏用url去传json过去.这里遇到如何js生成json字符串和后台接收时候如何转换成json对象. 这里先把一个检查json格式的工具提供大家,我是用这个去检查自己构造的json是否correct. 地址:<a href:http://www.bejson.com/>http://www.bejson.com/</a>个人觉得蛮好用的,简单方便. 接下来说说我们写javascript时候如何去处理json呢.以

Newtonsoft.Json.dll 反序列化JSON字符串

上一篇JSON博客<JSON入门级学习小结--JSON数据结构>中已对JSON做了简单介绍,JSON字符串数组数据样式大概是这样子的: 如今因为项目需求(asp.net web网站,前台向后台传递JSON数据,并对JSON数据处理,详述见博客< <项目经验>--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中 >),需要对传递的JSON数据反序列化.于是从网上找了许多JSON反序列化的例子,最终决定使用New

csharp:using Newtonsoft.Json.Net2.0 in .net 2.0 webform

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

csharp:.net 3.5 using System.Runtime.Serialization.Json read json

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C#.

/// <summary> ///參考: http://james.newtonking.com/json/help/index.html# /// 塗聚文(Geovin Du) 20141228 /// 捷為工作室 /// </summary> public partial class _Default : System.Web.UI.Page { Geovindu_TimeLineProjectInfo geovindu_TimeLineProjectInfo = new Ge