實用C 中任意型別資料轉成JSON格式資料輸出

2021-05-22 13:55:22 字數 1963 閱讀 2405

///

/// list轉成json

///

///

///

///

///

///

/// 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字串

///

/// datatable轉成json

///

///

///

///

///

/// datareader轉換為json

///

/// datareader物件

/// json字串

///

/// dataset轉換為json

///

/// dataset物件

/// json字串

public static string tojson(dataset dataset)

jsonstring = jsonstring.trimend(',');

return jsonstring + "}";

}///

/// 過濾特殊字元

///

///

///

///

/// 格式化字元型、日期型、布林型

///

///

///

///

private static string stringformat(string str, type type)

else if (type == typeof(datetime))

else if (type == typeof(bool))

return str;

}

C 中任意型別資料轉成JSON格式

list轉成json public static string listtojson ilistlist,string jsonname if i list.count 1 return json.tostring list轉成json public static string listtojson...

C 中任意型別資料轉成JSON格式資料輸出

list轉成json public static string listtojson ilistlist,string jsonname if i list.count 1 return json.tostring list轉成json public static string listtojson...

C 中任意型別資料轉成JSON格式資料輸出

code 01.02.list轉成json 03.04.05.06.07.08.public static stringlisttojson ilistlist,stringjsonname 09.30.32.if i33.36.37.39.returnjson.tostring 40.41.42....