/// 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
}
}
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;
}
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格式資料輸出
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....