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.///
43.///list轉成json
44.///
45.///
46.///
47.///
48.public
static
stringlisttojson(ilistlist)
49.53.
54.///
55.///物件轉換為json字串
56.///
57.///物件
58.///json字串
59.public
static
stringtojson(objectjsonobject)
60.71.else
if(objectvalueis
string)
72.75.else
if(objectvalueisienumerable)
76.79.else
80.83.jsonstring+="/""+tojson(propertyinfo[i].name)+"/":"+value+",";
84.}
85.jsonstring.remove(jsonstring.length-1,jsonstring.length);
86.returnjsonstring+"}";
87.}
88.89.///
90.///物件集合轉換json
91.///
92.///集合物件
93.///json字串
94.public
static
stringtojson(ienumerablearray)
95.101.jsonstring.remove(jsonstring.length-1,jsonstring.length);
102.returnjsonstring+"]";
103.}
104.
105.///
106.///普通集合轉換json
107.///
108.///集合物件
109.///json字串
110.public
static
stringtoarraystring(ienumerablearray)
111.
117.jsonstring.remove(jsonstring.length-1,jsonstring.length);
118.returnjsonstring+"]";
119.}
120.
121.///
122.///datatable轉換為json
123.///
124.///datatable物件
125.///json字串
126.public
static
stringtojson(datatabledt)
127.
145.else
146.
149.}
151.}
152.jsonstring.remove(jsonstring.length-1,1);
154.returnjsonstring.tostring();
155.}
156.
157.///
158.///datatable轉成json
159.///
160.///
161.///
162.///
163.public
static
stringtojson(datatabledt,stringjsonname)
164.
182.}
184.if(i185.
188.}
189.}
191.returnjson.tostring();
192.}
193.
194.///
195.///datareader轉換為json
196.///
197.///datareader物件
198.///json字串
199.public
static
stringtojson(dbdatareaderdatareader)
200.
217.else
218.
221.}
223.}
224.datareader.close();
225.jsonstring.remove(jsonstring.length-1,1);
227.returnjsonstring.tostring();
228.}
229.
230.///
231.///dataset轉換為json
232.///
233.///dataset物件
234.///json字串
235.public
static
stringtojson(datasetdataset)
236.
242.jsonstring=jsonstring.trimend(',');
243.returnjsonstring+"}";
244.}
245.
246.///
247.///過濾特殊字元
248.///
249.///
250.///
251.private
static
stringstring2json(strings)
252.
278.}
279.returnsb.tostring();
280.}
281.
282.///
283.///格式化字元型、日期型、布林型
284.///
285.///
286.///
287.///
288.private
static
stringstringformat(stringstr,typetype)
289.
295.else
if(type==typeof(datetime))
296.
299.else
if(type==typeof(bool))
300.
303.returnstr;
304.}
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 list轉成json public static string listtojson ilistlist 物件轉換為json字串 物件 json字串 public static string tojson object jsonobject else if objectvalu...
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...