自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

數(shù)據(jù)庫里的記錄與json之間如何轉(zhuǎn)換

數(shù)據(jù)庫
數(shù)據(jù)庫在當(dāng)今社會(huì)中已經(jīng)成為了一個(gè)必不可少的一份子,數(shù)據(jù)庫對社會(huì)的高速發(fā)展作出了很多貢獻(xiàn),帶動(dòng)著技術(shù)的進(jìn)步,本文中將為大家?guī)頂?shù)據(jù)庫里的記錄與json之間如何轉(zhuǎn)換。

數(shù)據(jù)庫里的記錄與json之間轉(zhuǎn)換。代碼如下:

  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Data;
  using System.Data.SqlClient;
  namespace OTC.Utility
  ...{
  public sealed class JSONHelper
  ...{
  /**////
  /// 獲取JSON字符串
  ///
  /// 值
  /// 數(shù)據(jù)表名
  ///
  public static string GetJSON(SqlDataReader drValue, string strTableName)
  ...{
  StringBuilder sb = new StringBuilder();
  sb.AppendLine("{");
  sb.AppendLine(" " + strTableName + ":{");
  sb.AppendLine(" records:[");
  try
  ...{
  while (drValue.Read())
  ...{
  sb.Append(" {");
  for (int i = 0; i < drValue.FieldCount; i++)
  ...{
  sb.AppendFormat(""{0}":"{1}",", drValue.GetName(i), drValue.GetValue(i));
  }
  sb.Remove(sb.ToString().LastIndexOf(’,’), 1);
  sb.AppendLine("},");
  }
  sb.Remove(sb.ToString().LastIndexOf(’,’), 1);
  }
  catch(Exception ex)
  ...{
  throw new Exception(ex.Message);
  }
  finally
  ...{
  drValue.Close();
  }
  sb.AppendLine(" ]");
  sb.AppendLine(" }");
  sb.AppendLine(" };");
  return sb.ToString();
  }
  }
  }

接下來你只需要傳一個(gè)SqlDataReader對象就可以了。
到這里數(shù)據(jù)庫里的記錄與json之間的轉(zhuǎn)換就可以實(shí)現(xiàn)了,通過上文中的代碼,數(shù)據(jù)庫里的記錄與json之間的轉(zhuǎn)換就容易很多了,二者之間的轉(zhuǎn)換的介紹主要是以代碼的形式展現(xiàn)在大家面前,對于沒有很多數(shù)據(jù)庫知識(shí)的初學(xué)者來說可能比較不容易理解,希望大家能夠深入其中去學(xué)習(xí)。

【編輯推薦】

  1. 詳解Oracle數(shù)據(jù)庫備份不同的恢復(fù)特性
  2. Access數(shù)據(jù)庫成功導(dǎo)入Oracle庫方法
  3. Oracle數(shù)據(jù)庫中使用外部表的心得
責(zé)任編輯:迎迎 來源: IT專家網(wǎng)論壇
相關(guān)推薦

2009-06-15 15:10:02

Java數(shù)據(jù)轉(zhuǎn)換JSON

2010-04-06 11:39:17

Oracle數(shù)據(jù)庫

2010-05-05 14:44:50

Oracle數(shù)據(jù)庫

2010-04-08 16:13:34

Oracle數(shù)據(jù)庫

2009-06-17 09:29:22

2010-08-10 10:07:29

DB2 數(shù)據(jù)庫

2019-03-25 20:31:58

IP地址轉(zhuǎn)換數(shù)字

2010-04-16 14:39:45

Oracle數(shù)據(jù)庫

2010-01-05 14:32:01

JSON 數(shù)據(jù)

2010-01-06 13:44:22

JSON的類庫

2011-05-19 10:29:40

對象數(shù)據(jù)庫關(guān)系數(shù)據(jù)庫

2018-09-11 17:13:23

MySQ數(shù)據(jù)庫重復(fù)記錄

2018-06-07 16:10:08

數(shù)據(jù)湖客戶互動(dòng)互動(dòng)分析

2009-03-26 14:53:16

DB2數(shù)據(jù)庫管理

2010-04-28 09:50:14

Oracle數(shù)據(jù)庫

2012-05-31 14:54:59

Hadoop大數(shù)據(jù)

2012-11-09 13:42:29

數(shù)據(jù)庫數(shù)據(jù)大數(shù)據(jù)

2012-05-15 11:29:41

數(shù)據(jù)庫

2011-04-06 17:35:17

Access數(shù)據(jù)庫空記錄

2010-01-05 14:49:03

JSON格式
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)