豆瓣API查询和显示图书的信息

使用豆瓣书籍API获取json类型的数据 由于需要,自己要写一个书籍管理系统,但是大量的书籍录入太费时间和精力;所以使用了豆瓣提供的api,下面是过程,从一个什么都不懂的基础来记录。 1.进入豆瓣为开发者提供的网站 https://developers.douban.com/wiki/?title=book_v2  我需要的是图书api 2.使用java代码给发送get请求 /** * 使用isbn 阅读详情

第一步:GetDataSource.cs类,用来通过HTTP协议从网络获取json文件,并通过文件流操作将json转化为string类型返回

第二步:通过c#语言在visual studio上画图形界面

第三步:引用”using Newtonsoft.Json.Linq;”,使用JObject来解析返回的string类型的json文件,获取符合关键字”q”的所有图书
遍历文件获取图书信息,将内容添加带List集合上,并绑定到datagridview.显示在窗体上;

第四步:通过传参数(图书的API),获取每本图书的信息,并显示在WinForm窗体上。

第五步:修改程序,使用多线程和委托技术,防止在获取大量数据时候界面卡死情况。


Books.cs

 public class Books
    {
        /// <summary>
        ///     书名
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        ///     作者
        /// </summary>
        public string Author { get; set; }

        /// <summary>
        ///     API地址
        /// </summary>
        public string Url { get; set; }

        /// <summary>
        ///     页数
        /// </summary>
        public string Pages { get; set; }

        /// <summary>
        ///     价格
        /// </summary>
        public string Price { get; set; }

        /// <summary>
        ///     序号
        /// </summary>
        public int Index { get; set; }
    }

GetDataSource.cs

  public class GetDataSource
    {
        /// <summary>
        ///     通过http协议从网络上获取json文件内容
        /// </summary>
        /// <param name="url">API地址</param>
        /// <returns>将json内容以string类型返回</returns>
        public string GetJsonFile(string url)
        {
            HttpWebRequest myRequest = null;
            HttpWebResponse myHttpResponse = null;
            string getUrl = url.Replace(@"\", "").Trim();
            myRequest = (HttpWebRequest) WebRequest.Create(getUrl);
            myHttpResponse = (HttpWebResponse) myRequest.GetResponse();
            var reader = new StreamReader(myHttpResponse.GetResponseStream(), Encoding.UTF8);
            string jsonFile = reader.ReadToEnd();
            reader.Close();
            myHttpResponse.Close();
            return jsonFile;
        }

        /// <summary>
        ///     通过标签获得图书信息
        /// </summary>
        /// <param name="tags">标签</param>
        /// <returns>将json内容以string类型返回</returns>
        public string GetTagsInfo(string tags)
        {
            string temp = "https://api.douban.com/v2/book/search?q=" + tags + "&start=0&count=100";
            var myRequest = (HttpWebRequest) WebRequest.Create(temp);
            var myHttpResponse = (HttpWebResponse) myRequest.GetResponse();
            var reader = new StreamReader(myHttpResponse.GetResponseStream(), Encoding.UTF8);
            string tagsFile = reader.ReadToEnd();
            reader.Close();
            myHttpResponse.Close();
            return tagsFile;
        }
    }

ReadAPIForm.Designer.cs

   partial class ReadAPIForm
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ReadAPIForm));
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btnSearch = new System.Windows.Forms.Button();
            this.tbSearch = new System.Windows.Forms.TextBox();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.dgvBookInfo = new System.Windows.Forms.DataGridView();
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column4 = new System.Windows.Forms.DataGridViewLinkColumn();
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.panel1 = new System.Windows.Forms.Panel();
            this.richTbSummery = new System.Windows.Forms.RichTextBox();
            this.btnCancle = new System.Windows.Forms.Button();
            this.labelBookPrice = new System.Windows.Forms.Label();
            this.labelBookPages = new System.Windows.Forms.Label();
            this.labelBookBinding = new System.Windows.Forms.Label();
            this.labelBookPublishDate = new System.Windows.Forms.Label();
            this.labelBookPublisher = new System.Windows.Forms.Label();
            this.labelBookTranslator = new System.Windows.Forms.Label();
            this.labelBookAuthor = new System.Windows.Forms.Label();
            this.labelBookID = new System.Windows.Forms.Label();
            this.labelBookName = new System.Windows.Forms.Label();
            this.labelSummery = new System.Windows.Forms.Label();
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.labelPrice = new System.Windows.Forms.Label();
            this.labelPages = new System.Windows.Forms.Label();
            this.labelBinding = new System.Windows.Forms.Label();
            this.labelPubTime = new System.Windows.Forms.Label();
            this.labelPublisher = new System.Windows.Forms.Label();
            this.labelTrans = new System.Windows.Forms.Label();
            this.labelAuthor = new System.Windows.Forms.Label();
            this.labelID = new System.Windows.Forms.Label();
            this.labelTitle = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvBookInfo)).BeginInit();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btnSearch);
            this.groupBox1.Controls.Add(this.tbSearch);
            this.groupBox1.Controls.Add(this.pictureBox1);
            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
            this.groupBox1.Location = new System.Drawing.Point(0, 0);
            this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.groupBox1.Size = new System.Drawing.Size(747, 98);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            // 
            // btnSearch
            // 
            this.btnSearch.Location = new System.Drawing.Point(452, 48);
            this.btnSearch.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.btnSearch.Name = "btnSearch";
            this.btnSearch.Size = new System.Drawing.Size(100, 29);
            this.btnSearch.TabIndex = 2;
            this.btnSearch.Text = "搜索";
            this.btnSearch.UseVisualStyleBackColor = true;
            this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
            // 
            // tbSearch
            // 
            this.tbSearch.Location = new System.Drawing.Point(200, 48);
            this.tbSearch.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.tbSearch.Name = "tbSearch";
            this.tbSearch.Size = new System.Drawing.Size(241, 25);
            this.tbSearch.TabIndex = 1;
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
            this.pictureBox1.Location = new System.Drawing.Point(69, 25);
            this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(67, 62);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // dgvBookInfo
            // 
            this.dgvBookInfo.AllowUserToResizeRows = false;
            this.dgvBookInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvBookInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6});
            this.dgvBookInfo.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dgvBookInfo.Location = new System.Drawing.Point(0, 98);
            this.dgvBookInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.dgvBookInfo.Name = "dgvBookInfo";
            this.dgvBookInfo.RowHeadersVisible = false;
            this.dgvBookInfo.RowTemplate.Height = 23;
            this.dgvBookInfo.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dgvBookInfo.Size = new System.Drawing.Size(747, 521);
            this.dgvBookInfo.TabIndex = 1;
            this.dgvBookInfo.Visible = false;
            this.dgvBookInfo.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvBookInfo_CellContentClick);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Index";
            this.Column1.FillWeight = 76.14214F;
            this.Column1.HeaderText = "序号";
            this.Column1.Name = "Column1";
            this.Column1.Width = 25;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Title";
            this.Column2.FillWeight = 104.7716F;
            this.Column2.HeaderText = "书名";
            this.Column2.Name = "Column2";
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "Author";
            this.Column3.FillWeight = 104.7716F;
            this.Column3.HeaderText = "作者";
            this.Column3.Name = "Column3";
            // 
            // Column4
            // 
            this.Column4.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.Column4.DataPropertyName = "Url";
            this.Column4.FillWeight = 104.7716F;
            this.Column4.HeaderText = "图书API";
            this.Column4.Name = "Column4";
            this.Column4.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Column4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "Pages";
            this.Column5.FillWeight = 104.7716F;
            this.Column5.HeaderText = "页数";
            this.Column5.Name = "Column5";
            this.Column5.Width = 54;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "Price";
            this.Column6.FillWeight = 104.7716F;
            this.Column6.HeaderText = "价格";
            this.Column6.Name = "Column6";
            this.Column6.Width = 54;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.richTbSummery);
            this.panel1.Controls.Add(this.btnCancle);
            this.panel1.Controls.Add(this.labelBookPrice);
            this.panel1.Controls.Add(this.labelBookPages);
            this.panel1.Controls.Add(this.labelBookBinding);
            this.panel1.Controls.Add(this.labelBookPublishDate);
            this.panel1.Controls.Add(this.labelBookPublisher);
            this.panel1.Controls.Add(this.labelBookTranslator);
            this.panel1.Controls.Add(this.labelBookAuthor);
            this.panel1.Controls.Add(this.labelBookID);
            this.panel1.Controls.Add(this.labelBookName);
            this.panel1.Controls.Add(this.labelSummery);
            this.panel1.Controls.Add(this.pictureBox2);
            this.panel1.Controls.Add(this.labelPrice);
            this.panel1.Controls.Add(this.labelPages);
            this.panel1.Controls.Add(this.labelBinding);
            this.panel1.Controls.Add(this.labelPubTime);
            this.panel1.Controls.Add(this.labelPublisher);
            this.panel1.Controls.Add(this.labelTrans);
            this.panel1.Controls.Add(this.labelAuthor);
            this.panel1.Controls.Add(this.labelID);
            this.panel1.Controls.Add(this.labelTitle);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 98);
            this.panel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(747, 521);
            this.panel1.TabIndex = 2;
            this.panel1.Visible = false;
            // 
            // richTbSummery
            // 
            this.richTbSummery.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.richTbSummery.Location = new System.Drawing.Point(69, 365);
            this.richTbSummery.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.richTbSummery.Name = "richTbSummery";
            this.richTbSummery.ReadOnly = true;
            this.richTbSummery.Size = new System.Drawing.Size(660, 140);
            this.richTbSummery.TabIndex = 22;
            this.richTbSummery.Text = "";
            // 
            // btnCancle
            // 
            this.btnCancle.Location = new System.Drawing.Point(631, 8);
            this.btnCancle.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.btnCancle.Name = "btnCancle";
            this.btnCancle.Size = new System.Drawing.Size(100, 29);
            this.btnCancle.TabIndex = 21;
            this.btnCancle.Text = "返回";
            this.btnCancle.UseVisualStyleBackColor = true;
            this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
            // 
            // labelBookPrice
            // 
            this.labelBookPrice.AutoSize = true;
            this.labelBookPrice.Location = new System.Drawing.Point(401, 331);
            this.labelBookPrice.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookPrice.Name = "labelBookPrice";
            this.labelBookPrice.Size = new System.Drawing.Size(55, 15);
            this.labelBookPrice.TabIndex = 20;
            this.labelBookPrice.Text = "label9";
            // 
            // labelBookPages
            // 
            this.labelBookPages.AutoSize = true;
            this.labelBookPages.Location = new System.Drawing.Point(401, 296);
            this.labelBookPages.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookPages.Name = "labelBookPages";
            this.labelBookPages.Size = new System.Drawing.Size(55, 15);
            this.labelBookPages.TabIndex = 19;
            this.labelBookPages.Text = "label8";
            // 
            // labelBookBinding
            // 
            this.labelBookBinding.AutoSize = true;
            this.labelBookBinding.Location = new System.Drawing.Point(401, 268);
            this.labelBookBinding.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookBinding.Name = "labelBookBinding";
            this.labelBookBinding.Size = new System.Drawing.Size(55, 15);
            this.labelBookBinding.TabIndex = 18;
            this.labelBookBinding.Text = "label7";
            // 
            // labelBookPublishDate
            // 
            this.labelBookPublishDate.AutoSize = true;
            this.labelBookPublishDate.Location = new System.Drawing.Point(401, 228);
            this.labelBookPublishDate.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookPublishDate.Name = "labelBookPublishDate";
            this.labelBookPublishDate.Size = new System.Drawing.Size(55, 15);
            this.labelBookPublishDate.TabIndex = 17;
            this.labelBookPublishDate.Text = "label6";
            // 
            // labelBookPublisher
            // 
            this.labelBookPublisher.AutoSize = true;
            this.labelBookPublisher.Location = new System.Drawing.Point(401, 191);
            this.labelBookPublisher.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookPublisher.Name = "labelBookPublisher";
            this.labelBookPublisher.Size = new System.Drawing.Size(55, 15);
            this.labelBookPublisher.TabIndex = 16;
            this.labelBookPublisher.Text = "label5";
            // 
            // labelBookTranslator
            // 
            this.labelBookTranslator.AutoSize = true;
            this.labelBookTranslator.Location = new System.Drawing.Point(401, 152);
            this.labelBookTranslator.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookTranslator.Name = "labelBookTranslator";
            this.labelBookTranslator.Size = new System.Drawing.Size(55, 15);
            this.labelBookTranslator.TabIndex = 15;
            this.labelBookTranslator.Text = "label4";
            // 
            // labelBookAuthor
            // 
            this.labelBookAuthor.AutoSize = true;
            this.labelBookAuthor.Location = new System.Drawing.Point(401, 121);
            this.labelBookAuthor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookAuthor.Name = "labelBookAuthor";
            this.labelBookAuthor.Size = new System.Drawing.Size(55, 15);
            this.labelBookAuthor.TabIndex = 14;
            this.labelBookAuthor.Text = "label3";
            // 
            // labelBookID
            // 
            this.labelBookID.AutoSize = true;
            this.labelBookID.Location = new System.Drawing.Point(401, 85);
            this.labelBookID.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookID.Name = "labelBookID";
            this.labelBookID.Size = new System.Drawing.Size(55, 15);
            this.labelBookID.TabIndex = 13;
            this.labelBookID.Text = "label2";
            // 
            // labelBookName
            // 
            this.labelBookName.AutoSize = true;
            this.labelBookName.Location = new System.Drawing.Point(401, 50);
            this.labelBookName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBookName.Name = "labelBookName";
            this.labelBookName.Size = new System.Drawing.Size(55, 15);
            this.labelBookName.TabIndex = 12;
            this.labelBookName.Text = "label1";
            // 
            // labelSummery
            // 
            this.labelSummery.AutoSize = true;
            this.labelSummery.Location = new System.Drawing.Point(20, 365);
            this.labelSummery.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelSummery.Name = "labelSummery";
            this.labelSummery.Size = new System.Drawing.Size(52, 15);
            this.labelSummery.TabIndex = 10;
            this.labelSummery.Text = "概要:";
            // 
            // pictureBox2
            // 
            this.pictureBox2.Location = new System.Drawing.Point(16, 24);
            this.pictureBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(289, 322);
            this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox2.TabIndex = 9;
            this.pictureBox2.TabStop = false;
            // 
            // labelPrice
            // 
            this.labelPrice.AutoSize = true;
            this.labelPrice.Location = new System.Drawing.Point(339, 331);
            this.labelPrice.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelPrice.Name = "labelPrice";
            this.labelPrice.Size = new System.Drawing.Size(52, 15);
            this.labelPrice.TabIndex = 8;
            this.labelPrice.Text = "价格:";
            // 
            // labelPages
            // 
            this.labelPages.AutoSize = true;
            this.labelPages.Location = new System.Drawing.Point(339, 296);
            this.labelPages.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelPages.Name = "labelPages";
            this.labelPages.Size = new System.Drawing.Size(52, 15);
            this.labelPages.TabIndex = 7;
            this.labelPages.Text = "页数:";
            // 
            // labelBinding
            // 
            this.labelBinding.AutoSize = true;
            this.labelBinding.Location = new System.Drawing.Point(339, 268);
            this.labelBinding.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelBinding.Name = "labelBinding";
            this.labelBinding.Size = new System.Drawing.Size(52, 15);
            this.labelBinding.TabIndex = 6;
            this.labelBinding.Text = "装帧:";
            // 
            // labelPubTime
            // 
            this.labelPubTime.AutoSize = true;
            this.labelPubTime.Location = new System.Drawing.Point(307, 228);
            this.labelPubTime.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelPubTime.Name = "labelPubTime";
            this.labelPubTime.Size = new System.Drawing.Size(82, 15);
            this.labelPubTime.TabIndex = 5;
            this.labelPubTime.Text = "出版时间:";
            // 
            // labelPublisher
            // 
            this.labelPublisher.AutoSize = true;
            this.labelPublisher.Location = new System.Drawing.Point(323, 191);
            this.labelPublisher.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelPublisher.Name = "labelPublisher";
            this.labelPublisher.Size = new System.Drawing.Size(67, 15);
            this.labelPublisher.TabIndex = 4;
            this.labelPublisher.Text = "出版社:";
            // 
            // labelTrans
            // 
            this.labelTrans.AutoSize = true;
            this.labelTrans.Location = new System.Drawing.Point(339, 152);
            this.labelTrans.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelTrans.Name = "labelTrans";
            this.labelTrans.Size = new System.Drawing.Size(52, 15);
            this.labelTrans.TabIndex = 3;
            this.labelTrans.Text = "翻译:";
            // 
            // labelAuthor
            // 
            this.labelAuthor.AutoSize = true;
            this.labelAuthor.Location = new System.Drawing.Point(339, 121);
            this.labelAuthor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelAuthor.Name = "labelAuthor";
            this.labelAuthor.Size = new System.Drawing.Size(52, 15);
            this.labelAuthor.TabIndex = 2;
            this.labelAuthor.Text = "作者:";
            // 
            // labelID
            // 
            this.labelID.AutoSize = true;
            this.labelID.Location = new System.Drawing.Point(355, 85);
            this.labelID.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelID.Name = "labelID";
            this.labelID.Size = new System.Drawing.Size(38, 15);
            this.labelID.TabIndex = 1;
            this.labelID.Text = "ID:";
            // 
            // labelTitle
            // 
            this.labelTitle.AutoSize = true;
            this.labelTitle.Location = new System.Drawing.Point(339, 50);
            this.labelTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            this.labelTitle.Name = "labelTitle";
            this.labelTitle.Size = new System.Drawing.Size(52, 15);
            this.labelTitle.TabIndex = 0;
            this.labelTitle.Text = "书名:";
            // 
            // ReadAPIForm
            // 
            this.AcceptButton = this.btnSearch;
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(747, 619);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.dgvBookInfo);
            this.Controls.Add(this.groupBox1);
            this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.Name = "ReadAPIForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "豆瓣图书阅读器";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvBookInfo)).EndInit();
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.Button btnSearch;
        private System.Windows.Forms.TextBox tbSearch;
        private System.Windows.Forms.DataGridView dgvBookInfo;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label labelSummery;
        private System.Windows.Forms.PictureBox pictureBox2;
        private System.Windows.Forms.Label labelPrice;
        private System.Windows.Forms.Label labelPages;
        private System.Windows.Forms.Label labelBinding;
        private System.Windows.Forms.Label labelPubTime;
        private System.Windows.Forms.Label labelPublisher;
        private System.Windows.Forms.Label labelTrans;
        private System.Windows.Forms.Label labelAuthor;
        private System.Windows.Forms.Label labelID;
        private System.Windows.Forms.Label labelTitle;
        private System.Windows.Forms.Label labelBookPrice;
        private System.Windows.Forms.Label labelBookPages;
        private System.Windows.Forms.Label labelBookBinding;
        private System.Windows.Forms.Label labelBookPublishDate;
        private System.Windows.Forms.Label labelBookPublisher;
        private System.Windows.Forms.Label labelBookTranslator;
        private System.Windows.Forms.Label labelBookAuthor;
        private System.Windows.Forms.Label labelBookID;
        private System.Windows.Forms.Label labelBookName;
        private System.Windows.Forms.Button btnCancle;
        private System.Windows.Forms.RichTextBox richTbSummery;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
        private System.Windows.Forms.DataGridViewLinkColumn Column4;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
    }

ReadAPIForm.cs

 public partial class ReadAPIForm : Form
    {
        public ReadAPIForm()
        {
            InitializeComponent();
        }

        /// <summary>
        ///     搜索按钮
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            var thread = new Thread(ThreadSearch);
            thread.IsBackground = true;
            thread.Start();
        }

        private void ThreadSearch()
        {
            Invoke(new Action(SearchBooks));
        }

        /// <summary>
        ///     搜索图书信息
        /// </summary>
        private void SearchBooks()
        {
            try
            {
                if (!string.IsNullOrEmpty(tbSearch.Text))
                {
                    dgvBookInfo.Visible = true;
                    var list = new List<Books>();
                    Invoke((MethodInvoker) delegate
                    {
                        var ds = new GetDataSource();
                        JObject reader = JObject.Parse(ds.GetTagsInfo(tbSearch.Text)); //使用Object读json字符串

                        IEnumerable<JToken> temp = from file in reader["books"].Children()
                            select file;
                        foreach (JToken tempFile in temp)
                        {
                            var book = new Books();
                            book.Title = tempFile["title"].ToString().Trim();
                            if (tempFile["author"].ToString().Trim() == "[]")
                            {
                                book.Author = tempFile["author"].ToString().Trim();
                            }
                            else
                            {
                                book.Author = tempFile["author"][0].ToString().Trim();
                            }
                            book.Url = tempFile["url"].ToString().Trim();
                            book.Pages = tempFile["pages"].ToString().Trim();
                            book.Price = tempFile["price"].ToString().Trim();
                            book.Index = list.Count + 1;
                            list.Add(book);
                        }
                    });
                    if (list.Count == 0)
                    {
                        dgvBookInfo.Visible = false;
                        MessageBox.Show("没有查询到相关信息或者查询信息!!");
                    }
                    else
                    {
                        Invoke((MethodInvoker) delegate { dgvBookInfo.DataSource = list; //数据绑定到datagridview   
                        });
                    }
                }
                else
                {
                    MessageBox.Show("请输入信息后在查找!!");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("没有查询到相关信息!!");
            }
        }

        /// <summary>
        ///     点击查询结果列表,获取图书详细信息
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void dgvBookInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                dgvBookInfo.Visible = false;
                panel1.Visible = true;
                int index = dgvBookInfo.CurrentRow.Index;
                string temp = dgvBookInfo.Rows[index].Cells[2].Value.ToString();
                var getdata = new GetDataSource();
                JObject reader = JObject.Parse(getdata.GetJsonFile(temp));
                labelBookName.Text = reader["title"].ToString().Trim();
                labelBookID.Text = reader["id"].ToString().Trim();
                labelBookAuthor.Text = "";
                for (int i = 0; i < reader["author"].Count(); i++)
                {
                    if (reader["author"].ToString().Trim() == "[]")
                    {
                        labelBookAuthor.Text = reader["author"].ToString().Trim();
                    }
                    else
                    {
                        labelBookAuthor.Text += reader["author"][i].ToString().Trim();
                    }
                }
                labelBookPublisher.Text = reader["publisher"].ToString().Trim();
                labelBookPublishDate.Text = reader["pubdate"].ToString().Trim();
                labelBookBinding.Text = reader["binding"].ToString().Trim();
                labelBookPages.Text = reader["pages"].ToString().Trim();
                labelBookPrice.Text = reader["price"].ToString().Trim();
                pictureBox2.ImageLocation = reader["images"]["large"].ToString().Trim();
                richTbSummery.Text = reader["summary"].ToString().Trim();
                labelBookTranslator.Text = "";
                for (int i = 0; i < reader["translator"].Count(); i++)
                {
                    if (reader["translator"].ToString().Trim() == "[]")
                    {
                        labelBookTranslator.Text = reader["translator"].ToString().Trim();
                    }
                    else
                    {
                        labelBookTranslator.Text += reader["translator"][0].ToString().Trim();
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("发生异常,请检查!");
            }
        }

        /// <summary>
        ///     返回按钮,隐藏显示的信息
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void btnCan
cle_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            dgvBookInfo.Visible = true;
        }
    }

运行结果如图:

这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述

2023年必备12书籍API推荐 Google Books为其API提供了详尽的文档,其中包含了丰富的示例和使用场景。此外,该API的嵌入式阅读器功能允许开发者将书籍内容嵌入到网站或Web应用中。 阅读详情

相关推荐

根据isbn获得图书的所有信息

根据isbn获得图书的所有信息

qq_43678748的博客 3163

豆瓣图书API

技术交流QQ群 277030213 豆瓣 api php 项目 https://github.com/wenyanjun/douban 豆瓣 api 地址 服务器地址 http://39.105.38.10:8081/ 1.top250 访问路径 book/top250?page=0 返回数据 { "coderYJ": "简书关注coderYJ 欢迎加QQ群讨论277030213", "code": 200, "msg": "请求成功", "data": { .

coderYJ的博客 1万+

豆瓣图书API - 使用Python进行图书信息查询

首先,我们需要注册一个豆瓣开发者账号,并创建一个应用程序。如果返回的JSON数据中存在"books"字段,说明有相关的图书信息。豆瓣图书API是豆瓣提供的一个接口,可以用于获取豆瓣图书的信息,例如图书的标题、作者、评分等。本文将介绍如何使用Python编程语言通过豆瓣图书API查询图书信息,并展示相应的源代码示例。通过以上代码,我们可以使用豆瓣图书API查询图书信息。库来发送HTTP请求,并使用获得的密钥访问豆瓣图书API。希望本文能帮助你了解如何使用Python通过豆瓣图书API查询图书信息。

TiCrystal的博客 2051

豆瓣最新能用的api合集总结

豆瓣网(Douban)作为一个集合了书籍、电影、音乐等多个领域的评论和评分平台,提供了丰富的API接口供开发者使用。通过这些API,开发者可以轻松地获取和处理豆瓣网上的各种数据,实现与豆瓣服务的无缝集成。本文将为您介绍最新的豆瓣API合集及其使用方法。接下来将详细介绍每个类别下的重要接口及其使用示例。

猫哥 的沉淀、积累、总结。天天学习,好好向上...c/c++,嵌入式 linux,Android,HarmonyOS,AIOT) 3万+

华硕天选3 win11+ubuntu20.04双硬盘双系统配置(包括ubuntu重启后无法成功进入、没有wifi图标的设置)

1、制作系统盘 2、分区 3、重启电脑按F2

baidu_38431960的博客 1万+

模型性能评估之 Friedman 检验与 Nemenyi 后续检验

前言 当我们提出一种算法,需要知道我们的算法和现在已有的算法相比,性能是否更优的时候,就需要用到模型性能评估的方法。本篇博客介绍一种模型性能评估的方法:Friedman 检验与 Nemenyi 后续检验。 该方法的特点是:可以进行多个算法的比较。下面看看具体的使用: 具体使用 1. 计算序值 假定我们用 D1D_1D1​、D2D_2D2​ 、D3D_3D3​ 和 D4D_4D4​ 四个数据集对算法 AAA、BBB、CCC 进行比较。首先需要得到每个算法在每个数据集上的测试结果,可以是准确率,也可以是均方误差

蕾欧娜与26的博客 1万+

android条形码的应用

扫描和识别条形码的android支持库 android支持扫描条形码。不过手里没有真机,无法理解该功能是一个应用,还是一个可API调用的功能。不过在网上找到一个免费开源的android处理条形码的库。见: http://code.google.com/p/zxing 可以作为应用安装到android上,见: http://code.google.com/p/zxing/wiki/Getti

jeans2012 539

从AND到XOR:5种门控电路在PrimeTime中的检查策略差异

本文深入探讨了AND、NAND、OR、NOR和XOR五种门控电路在PrimeTime静态时序分析中的检查策略差异。重点解析了XOR门控因其非单调性而无法被工具自动推断,需要工程师手动配置的特殊性,并提供了针对各类门控的配置模板与调试技巧,以确保时钟网络的完整性与芯片设计的可靠性。

rgv2345678的博客 269

java豆瓣查书api_如何通过豆瓣API获取图书和电影列表

一直在豆瓣上收藏看过的书和电影(其他功能基本没用过),准备做个页面可以同步显示豆瓣上收藏的所有图书和电影,这个功能可以通过豆瓣提供的API来实现,并不复杂,我只是做了简单的封装,需要的可以直接拿去用,有问题可以直接留言,运行后的效果看这里 Books 或这里我的豆瓣,因为豆瓣限制一分钟内访问次数不能超过40次,所以如果多人同时访问前面的链接可能看不到效果,再传个截图上来:几点说明:1.登录豆瓣...

weixin_39854951的博客 2107

NA400与昆仑通态MODBUS/TCP通讯调试说明

点击增加设备通道,弹出窗口进行设置,通道类型选择“0区输出继电器”,通道地址为1,通道个数为1,读写方式为读写。点击增加设备通道,弹出窗口进行设置,通道类型选择“4区输出寄存器”,数据类型选择“16位 无符号二进制”,通道地址为21001,通道个数为1,读写方式为读写。5.添加设备通道:双击莫迪康MODBUSTCP子设备,点击添加设备通道,根据Modbus规约地址表进行参数的设置,表格可在NAPro软件帮助中查看,如下图所示。然后可以在设备通道调试数据中观察到Q1的值为1,NW1的值678,表示通讯成功。

weixin_44281509的博客 2490

ios开发拒绝“玄学”Crash:从循环引用到脏内存,构建你的系统性排查思维模型

你申请了内存,写了数据,这块内存就是脏的。系统无法直接回收它,除非你显式释放,或者系统把它 swap 出去(但在 iOS 上,Compressed Memory 机制虽然能压缩,但不会像桌面系统那样频繁 swap 到磁盘,一旦压缩内存也撑不住,你也得挂)。所以,排查 OOM 的核心心法只有一条:不要问“哪里漏了”,要问“每一刻,留在这个页面上的内存,凭什么必须在这里?一旦内存水位线逼近阈值(不同机型不同,老机器可能 600MB 就危,新机器能抗 1.5GB),系统发个警告。

大模型大数据攻城狮的专栏 724

图书信息查询ISBN2.0

ISBN图书查询 自2019年5月8日公布isbn查询接口1.0至今,该图书数据查询服务已被调用八万余次,查得图书11653本,感谢一直使用和关心这个接口的朋友们! 目前网站域名将于2019年12月11日到期,qiaohaoforever.cn域名将停止服务,请目前还是使用此域名接口的朋友注意调整新的接口,如有不便之处请多包涵。 关于更新 图书信息查询isbn2.0接口新增了部分开发者感兴趣...

正版乔的博客 3383

I2C通信——时序图

本文用逻辑分析仪抓取主机I2C通信的时序图,抓取的过程是读某个寄存器的值。

weixin_43772611的博客 7353

开发实战分享|小程序扫码获取图书信息(内附详细教程)

作者:祈澈姑娘小程序扫码实现读取isbn,获取图书的各种信息接触到云函数已经有一段时间了,之前一直在看api,现在自己跟着网络上的资料和视频学习,受到豆瓣读书系列的启发,决定用云函数做一个项目,获取图书信息并存入云数据库。基本流程1.用户端小程序调用 wx.scanCode接口,获取到ISBN码。 2.使用ISBN码调用云函数,在请求云函数的时候,云函数会请求豆瓣的API,获取豆瓣图书信息。 3....

weixin_33676492的博客 6551

Vite 任意文件读取漏洞复现(CVE-2026-39363)

Vite开发服务器 WebSocket中的fetchModule方法未实施server.fs访问控制,导致攻击者可通过WebSocket连接并读取服务器上的任意文件(CVE-2026-39363)

iSee857的博客 219

RNA-seq分析:Step4(比对)

预处理之后的fastq文件,可以使用HISAT2软件将reads比对至参考基因组上。HISAT2软件将reads比对至参考基因组上的步骤如下:1. 对参考基因组进行建索引。对参考基因组进行预处理,生成索引文件,包括基因组序列的FM索引和SA索引。2. 将原始的reads进行预处理。包括去除接头序列、去除低质量的碱基,以及进行过滤,得到质量较高的、可靠的reads。3. 利用建立的FM索引和SA索引,将处理后的reads与参考基因组进行比对。首先,通过FM索引,快速找到与reads匹配的可能位置;

沉香best的博客 2599

Calibre-Web豆瓣插件配置指南:3步实现图书信息自动获取

Calibre-Web豆瓣数据获取插件是一个专门为图书管理爱好者设计的实用工具,能够自动从豆瓣网站抓取图书的完整元数据信息,包括书名、作者、出版社、封面图片、简介等关键信息,极大提升了图书管理的效率和准确性。 ## 插件功能与优势 该插件基于Python开发,采用网页抓取技术实现豆瓣图书数据的自动化获取。主要功能包括: - 自动匹配图书信息并填充元数据 - 支持封面图片代理下载和本地存储 -

gitblog_00065的博客 1045

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

识别图书ISBN号并输出查询结果的示例

识别图书ISBN号并输出查询结果的示例 识别图书ISBN号并输出查询结果的示例 - archfree的专栏 - 博客频道 - youkuaiyun.com识别图书ISBN号并输出查询结果的示例 分类: java 二维码识读 2011-02-11 23...

701

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

豆瓣服务 & API

豆瓣服务 & API 豆瓣服务 & API豆瓣服务 & API用豆瓣帐号登录 ······功能简介 开发流程推荐到豆瓣 (Bookmarklet) ······推荐到豆瓣...

266

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Calibre-Web豆瓣API插件:让你的电子书库重获新生

还在为Calibre-Web无法获取豆瓣书籍信息而烦恼吗?这个神奇的插件就是你的救星!✨ 它能通过网页抓取技术,自动为你的电子书库添加完整的书籍元数据,让管理变得更加轻松愉快。 ## 🎯 使用场景全解析 ### 1. 电子书爱好者必备 如果你拥有大量电子书,需要统一管理封面、作者、出版社等信息,这个插件就是你的得力助手。它能够: - 自动识别并下载书籍封面 - 完善作者、出版社等基本信息

gitblog_00974的博客 849

识别图书ISBN号并输出查询结果的示例 | Marshal's Blog

识别图书ISBN号并输出查询结果的示例 | Marshal's Blog 识别图书ISBN号并输出查询结果的示例 | Marshal's Blog识别图书ISBN号并输出查询结果的示例写了个技术原型,通过手机识别图书的ISBN条形码,然后通过豆瓣网的API,输出IS...

469

一个小插件,解决了我在豆瓣和图书馆之间反复横跳的问题

豆瓣图书馆查询助手是一款浏览器插件,可一键查询豆瓣图书在图书馆的馆藏情况。它能自动识别豆瓣页面的书名/ISBN,支持多省市图书馆查询,并直接显示结果,省去反复切换网页的麻烦。适合学生、研究者等经常使用图书馆的人群。插件已开源,安装简单,能大幅提升查书效率。

635

Android扫描图书ISBN号保存图书信息管理器

扫描部分利用的是Zxing的代码 https://github.com/zxing/zxing ,通过摄像头扫描条形码,根据ISBN获得的ISBN号,连接到豆瓣进行查询图书信息 http://developers.douban.com/wiki/?title=book_v2 ,解析返回来的数据,保存到本地。目前只是做了listiew和单本书籍信息显示,具体的查询还未有时间做。数据库字段已经添加多了

jiangyou050的专栏 5223

3分钟快速安装Calibre豆瓣元数据插件:免费获取中文图书信息的终极指南

对于使用Calibre管理电子书的用户来说,calibre-douban插件是一个不可或缺的元数据获取神器。这款强大的插件能够从豆瓣网站智能爬取图书信息,即使豆瓣官方API已经关闭,它依然能够为您提供完整的图书元数据,让您的电子书库更加专业和完善。 ## 📚 项目概览:为什么选择calibre-douban插件? 豆瓣作为中文图书信息最丰富的平台,包含了详尽的图书元数据:封面图片、作者信息、

gitblog_00270的博客 477

【2024更新】高效豆瓣图书元数据获取工具:Calibre插件完美替代方案

豆瓣图书API服务终止后,许多Calibre用户面临元数据获取困难。这款插件通过网页爬虫技术,绕过API限制,直接从豆瓣网站提取书籍信息,成为目前最稳定的豆瓣元数据获取方案。 ## 技术原理简析:插件如何工作? 工作流程图 插件采用三层架构设计: 1. 请求层:模拟浏览器发送搜索请求 2. 解析层:提取HTML中的书籍元数据 3. 适配层:转换为Calibre兼容格式 整个过程在本地完成,

gitblog_00604的博客 827
上一篇: JSON编码格式提交表单数据详解
下一篇: 基于Layui框架的NET后台管理系统
.NET跨平台
博客等级 码龄15年 6066粉丝 738原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值