c# 物件資料轉換json幫助類 jsonhelp
using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.collections.generic;
using system.text;
using system.collections;
using system.reflection;
using system.data.common;
/// ///listtojson 的摘要說明
///
public class gettojson
/// /// list轉成json
///
///
///
///
///
public static string listtojson(ilistlist, string jsonname)
}if (i < list.count - 1)}}
return json.tostring();
}/// /// list轉成json
///
///
///
///
public static string listtojson(ilistlist)
/// /// 物件轉換為json字串
///
/// 物件
/// json字串
public static string tojson(object jsonobject)
else if (objectvalue is string)
else if (objectvalue is ienumerable)
else
jsonstring += "\"" + tojson(propertyinfo[i].name) + "\":" + value + ",";
}jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "}";
}/// /// 物件集合轉換json
///
/// 集合物件
/// json字串
public static string tojson(ienumerable array)
jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "]";
}/// /// 普通集合轉換json
///
/// 集合物件
/// json字串
public static string toarraystring(ienumerable array)
jsonstring.remove(jsonstring.length - 1, jsonstring.length);
return jsonstring + "]";
}/// /// datatable轉換為json
///
/// datatable物件
/// json字串
public static string tojson(datatable dt)
else
}else
if (j < dt.columns.count - 1)
else}}
jsonstring.remove(jsonstring.length - 1, 1);
return jsonstring.tostring();
}/// /// datatable轉成json
///
///
///
///
public static string tojson(datatable dt, string jsonname)
}if (i < dt.rows.count - 1)}}
return json.tostring();
}// /// datareader轉換為json
///
/// datareader物件
/// json字串
public static string tojson(dbdatareader datareader)
else}}
datareader.close();
jsonstring.remove(jsonstring.length - 1, 1);
return jsonstring.tostring();
}/// /// dataset轉換為json
///
/// dataset物件
/// json字串
public static string tojson(dataset dataset)
jsonstring = jsonstring.trimend(',');
return jsonstring + "}";
}/// /// 過濾特殊字元
///
///
///
///
private static string string2json(string s)
}return sb.tostring();
}/// /// 格式化字元型、日期型、布林型
///
///
///
///
private static string stringformat(string str, type type)
else if (type == typeof(datetime))
else if (type == typeof(bool))
return str;
}}
轉換Json格式幫助類
using system using system.collections.generic using system.text using system.reflection using system.data using system.collections namespace aimscommo...
c 通用json幫助類
using system using system.data using system.text using system.collections.generic using system.reflection using system.data.common using system.collec...
C 處理資料型別轉換幫助類
using system using system.text namespace dotnet.utilities 連線text temp text 返回補足0的字串 return temp endregion region 各進製數間轉換 實現各進製數間的轉換。convertbase 15 10,...