//前后端传值时,数组类型数据无法直接传递,需要转换class="superseo">JSON,将JSON数组数据转为string类型,并通过“,”分割
string[] checkedCities = form["checkedCities"].ToString().Split(',');
List result = new List(FormatOrganizationName(checkedCities));
//传值时因出现了不必要的'/r/n'换行符和一些杂乱字母,用了正则表达式取到有用信息
/* public string[] FormatOrganizationName(string[] checkedCities)
{
for (int i=0; i
除了正则表达式,还可用其他方法提取需要的值(传递的是中文字符,所以正则筛选的是中文字符)
1.正则表达式
string after = Regex.Replace(before, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "")
2.返回新字符串
//选取原来字符串的起始位置beginIndex,取长度为length的字符,注意,数组起始下标为0
after = before.Substring(beginIndex,length)
如
"unhappy".substring(2) returns"happy
"hamburger".substring(3,8) returns "burge"
"smiles".substring(0,5) returns "smile"
3.直接去除
after = before.Replace('a','b','c')
前端传值时别忘了声明JSON字符串类型
getTotalCount() {
var self = this
request({
url: self.url + '/api/GlitchView/GetTotalCount',
method: 'get',
headers: {
'Authorization': 'Bearer ' + getToken(),
//作为请求头告诉服务端消息主体是序列化的JSON字符串
'Content-Type': 'application/json'
},
//消息主体是序列化的JSON字符串
contentType: "application/json",
params:{
listQuery:self.listQuery,
//将传输的数据转为JSON格式
checkedCities:JSON.stringify(self.checkedCities),
}
}).then(response => {
self.total = response
})
},
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)