admin 管理员组文章数量: 1086019
2023年12月18日发(作者:linux查看cpu使用率命令)
List
[html]1. public static string Obj2Json
2. {
3. try
4. {
5. ntractJsonSerializer serializer = new ntractJsonSerializer(e());
6. using (MemoryStream ms = new MemoryStream())
7. {
8. bject(ms, data);
9. return ing(y());
10. }
11. }
12. catch
13. {
14. return null;
15. }
16. }
public static string Obj2Json
[html]1. public static Object Json2Obj(String json,Type t)
2. {
3. try
4. {
5. ntractJsonSerializer serializer = new ntractJsonSerializer(t);
6. using (MemoryStream ms = new MemoryStream(es(json)))
7. {
8.
9. return ject(ms);
10. }
11. }
12. catch
13. {
14. return null;
15. }
16. }
public static Object Json2Obj(String json,Type t){ try { ntractJsonSerializer serializer = new ntractJsonSerializer(t); using (MemoryStream ms = new MemoryStream(es(json))) {
return ject(ms); } } catch { return null; }}DataTable 转Json
[html]1. public static string DataTable2Json(DataTable dt)
2. {
17. {
18. if (j < - 1)
19. {
20. (""" + s[j].ng() + "":" + """ + [i][j].ToString() + "",");
21. }
22. else if (j == - 1)
23. {
24. (""" + s[j].ng() + "":" + """ + [i][j].ToString() + """);
25. }
26. }
27. if (i == - 1)
28. {
29. ("} ");
30. }
31. else
32. {
33. ("}, ");
34. }
35. }
36. ("]}");
37. return ng();
38. }
39. else
40. {
41. return null;
42. }
43. }
///
1. public static class JsonTableHelper
2. {
3. ///
4. /// 返回对象序列化
5. ///
6. /// 源对象
7. ///
8. public static string ToJson(this object obj)
9. {
10. JavaScriptSerializer serialize = new JavaScriptSerializer();
11. return ize(obj);
12. }
13.
14. ///
15. /// 控制深度
16. ///
17. /// 源对象
18. /// 深度
13 foreach (DataColumn dc in s)14 {15 (Name, dr[Name]);16 }17 (drow);18
19 }20 //序列化
21 return ize(dic);22 }
版权声明:本文标题:C#中如何将List自定义转为Json格式及相关函数-DataContractJsonSe 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1702884154a434558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论