net core serialization and de-serialization and encountered several pit

Original: NET Core serialization and de-serialization and encountered several pit

Inside C # Before After serialization namespace directly introduced using JavaScriptSerializer jss = new JavaScriptSerializer (); can be used,

The net core which is not so used, we take a look at how to use.


nbsp;

1, and deserialize serialized.

2, at different points in the development of C #.


Serialization and de-serialization:

Similarly, in Nugetnbsp; the Newtonsoft.Json, cited below:

nbsp;


nbsp;

Used as follows:


// entity like sequences into the JSON
var = n-JSO Newtonsoft.Json.JsonConvert.SerializeObject (Data);

// deserialize the JSON
nbsp; the Model T = Newtonsoft.Json.JsonConvert.DeserializeObjectlt; the Tgt; (JSON);

 

Development with C # differences:

nbsp; 1, receives the foreground background value;

 C # background reception:

  • In the method of receiving directly inside the brackets;
  • Use Request [ldquo; rdquo specified name;];
  • Use of acquired body

nbsp; net core backstage reception:

  • In the method of receiving directly inside the brackets;
  • Use Request.Form [ldquo; rdquo specified name;];
  • Use of acquired body

nbsp;

2, the following files are not placed in the wwwroot

C # write:

  • Can be anywhere

net core literacy

  • Write: can be anywhere
  • Degree: For example, you can not read the image file is not in the wwwroot below, if you must read, you must dependency injection in Startup.cs, follows the original things do not move, app.UseStaticFiles in Configure the following methods (); below add the following code
       // set access files 
            app.UseStaticFiles ( new new StaticFileOptions 
            { 
                // profile in addition to the default wwwroot file static files folder file provided outside of the Web root directory through this configuration later, you can access the files in the upload file 
                FileProvider = new new PhysicalFileProvider ( 
                  Path.Combine (Directory.GetCurrentDirectory (), " Upload " )), the file name can Upload // replace any 
                RequestPath = " / Upload " , 
            });

nbsp;

3, access to the file path

C # Gets the file path:

  • System.Web.HttpContext.Current.Server.MapPath(applicationPath)

net core get file path

  • Web root to get the physical path through the injection IHostingEnvironment clients

nbsp;


nbsp;

There is more need to fill the pit, not list them here, and interested small partners can comment you stepped out of the pit below and we work together to fill in a blank.

nbsp;

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/11249438.html