没有合适的资源?快使用搜索试试~ 我知道了~
c#写的操作JSON的类c#写的操作JSON的类
资源推荐
资源详情
资源评论
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Reflection;
using System.Data.Common;
namespace ZGZY.Common
{
/// <summary>
/// JSON帮助类
/// </summary>
public class JsonHelper
{
#region 通用方法
/// <summary>
/// 格式化字符型、日期型、布尔型
/// </summary>
public static string StringFormat(string str, Type type)
{
if (type == typeof(string))
{
str = StringFilter(str);
str = "\"" + str + "\"";
}
else if (type == typeof(DateTime) || type == typeof(DateTime?))
{
str = "\"" + str + "\"";
}
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Reflection;
using System.Data.Common;
namespace ZGZY.Common
{
/// <summary>
/// JSON帮助类
/// </summary>
public class JsonHelper
{
#region 通用方法
/// <summary>
/// 格式化字符型、日期型、布尔型
/// </summary>
public static string StringFormat(string str, Type type)
{
if (type == typeof(string))
{
str = StringFilter(str);
str = "\"" + str + "\"";
}
else if (type == typeof(DateTime) || type == typeof(DateTime?))
{
str = "\"" + str + "\"";
}
else if (type == typeof(bool))
{
str = str.ToLower();
}
else if (type == typeof(Guid))
{
str = "\"" + str + "\"";
}
else if (type != typeof(string) && string.IsNullOrEmpty(str))
{
str = "\"" + str + "\"";
}
return str;
}
/// <summary>
/// 过滤字符串
/// </summary>
public static string StringFilter(string str)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
char c = str.ToCharArray()[i];
switch (c)
{
case '\"':
sb.Append("\\\""); break;
case '\\':
sb.Append("\\\\"); break;
{
str = str.ToLower();
}
else if (type == typeof(Guid))
{
str = "\"" + str + "\"";
}
else if (type != typeof(string) && string.IsNullOrEmpty(str))
{
str = "\"" + str + "\"";
}
return str;
}
/// <summary>
/// 过滤字符串
/// </summary>
public static string StringFilter(string str)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
char c = str.ToCharArray()[i];
switch (c)
{
case '\"':
sb.Append("\\\""); break;
case '\\':
sb.Append("\\\\"); break;
剩余11页未读,继续阅读
资源评论
ninghuizhang
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功