Take a look! This method is used to transmit a JSON data set to the background on the front-end page, for example, [{'A': '', 'B':" "},...] format data, split the data in the background, and import the data to the database in batches.
# Region JSON data conversion to a generic set (or entity) /// <summary> // convert a single JSON data record to an object // </Summary> /// <typeparam name = "T"> </typeparam> /// <Param name = "str"> escape character (Format: {: '', B:''}) </param> // <returns> </returns> Private Static t converttoentity <t> (string Str) {type T = typeof (t); object OBJ = activator. createinstance (t); var properties = T. getproperties (); string M = Str. trim ('{'). trim ('}'); string [] arr = m. split (','); (INT I = 0; I <arr. count (); I ++) {for (int K = 0; k <properties. count (); k ++) {string name = arr [I]. substring (0, arr [I]. indexof (":"); object value = arr [I]. substring (ARR [I]. indexof (":") + 1); If (properties [K]. name. equals (name) {If (properties [K]. propertytype. equals (typeof (INT) {properties [K]. setvalue (OBJ, convert. toint32 (value), null);} If (properties [K]. propertytype. equals (typeof (Str ING) {properties [K]. setvalue (OBJ, convert. tostring (value), null);} If (properties [K]. propertytype. equals (typeof (long) {properties [K]. setvalue (OBJ, convert. toint64 (value), null);} If (properties [K]. propertytype. equals (typeof (decimal) {properties [K]. setvalue (OBJ, convert. todecimal (value), null);} If (properties [K]. propertytype. equals (typeof (double) {properties [K]. setvalue (OBJ, convert. Todouble (value), null);} If (properties [K]. propertytype. equals (typeof (nullable <int>) {properties [K]. setvalue (OBJ, convert. toint32 (value), null);} If (properties [K]. propertytype. equals (typeof (nullable <decimal>) {properties [K]. setvalue (OBJ, convert. todecimal (value), null);} If (properties [K]. propertytype. equals (typeof (nullable <long>) {properties [K]. setvalue (OBJ, convert. toint64 (value ), Null);} If (properties [K]. propertytype. equals (typeof (nullable <double>) {properties [K]. setvalue (OBJ, convert. todouble (value), null);} If (properties [K]. propertytype. equals (typeof (nullable <datetime>) {properties [K]. setvalue (OBJ, convert. todatetime (value), null) ;}}return (t) OBJ ;} /// <summary> /// convert multiple JSON data to generic data /// </Summary> /// <typeparam name = "T"> </typeparam> /// <Param name = "JSO Narr "> escape character (Format: [{A:'', B: ''}, {A:'', B: ''}, {:'', b: ''}]) </param> // <returns> </returns> Public static list <t> converttolist <t> (this string jsonarr) {If (! String. isnullorempty (jsonarr) & jsonarr. startswith ("[") & jsonarr. endswith ("]") {type T = typeof (t); var properties = T. getproperties (); List <t> List = new list <t> (); string recive = jsonarr. trim ('['). trim (']'). replace ("'",""). replace ("\" "," "); string [] recivearr = recive. replace ("},{","};{"). split (';'); foreach (VAR item in recivearr) {t obj = converttoentity <t> (item); list. add (OBJ);} return list;} return NULL;} # endregion