Chinaunix首页 | 论坛 | 博客
  • 博客访问: 606493
  • 博文数量: 796
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 5095
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-10 09:43
文章分类

全部博文(796)

文章存档

2011年(1)

2008年(795)

我的朋友

分类:

2008-09-10 10:00:04

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace OTC.Utility
...{
public sealed class JSONHelper
...{
/**////
/// 获取JSON字符串
///
/// 值
/// 数据表名
///
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();
}
}
}


--------------------next---------------------

阅读(203) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~