Sometimes webapi may need to add <! to some fields with HTML or special characters (such as < > &/) when serializing XML. [cdata[]]> has prevented normal data from affecting XML, if you use an. aspx view that directly joins the <! when the field is bound in the foreground [Cdata[]]>,webapi only backstage code, that can only be done in the background, as follows.
1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Net; 5 using System.Net.Http; 6 using System.Net.Http.Formatting; 7 using System.Threading.Tasks; 8 using System.Web.Http; 9 using System.Xml; Ten using System.Xml.Serialization; Namespace Mvcapplication1.controllers 15 {16 public class Testcontroller:apicontroller HttpGet] [HttpPost] httpresponsemessage housetest (string city) 19 {20// To construct the data manually, this should be called construction data. $ var info = new Gethousecountinfo () {cityname = "Beijing", 24 Countinfo = new List<countinfo> () {27 New Countinfo () {Page Data = "2016-08-30", Housedetail = "description information 1111 etc. ... "32}, new Countinfo () {33 data = "2016-08-30", Housedetail = "description information 2222 etc. ... "+", Countinfo new () PNS A = "2016-08-30", Housedetail = "description Information 333 etc. ... "40} 41} 42}; 43//Serialized entity with assignment of var model = new Housecountroot {gethouseinfo = new Gethousecountinfo ()}; Model. Gethouseinfo.countinfo = info. Countinfo; The model. Result = ""; Model. Message = ""; Model. Gethouseinfo.cityname = info. CityName; Httpresponsemessage return new () {Content = n EW objectcontentThe results are as follows.
1 <?xml version= "1.0"?> 2
The entity attributes increase <! when ASP. NET Webapi is serialized as XML [cdata[]]> Prevent special characters