开发过程中使用到了vue框架进行前端批量数据的处理,将批量数据转换为json格式进行ajax传参时需要注意将vue数据源得到的json结果进行如下处理,webservice接收json数据时无法有效的识别双引号。
//错误的json格式 //error_json:'[{ "Module_id": "", "Project_id": "", "Feature_type": "", "Feature_name": "", "Calc_type": "", "Alarm_type": "", "Alarm_channel": "", "Int_param1": "", "Int_param2": "", "Owner": [], "Follower": [] }]' var feature_group_json = JSON.stringify(this.featureGroup); //正确的json格式 //success_json:'{"featureGroupJson":"[{ \'Module_id\': \'\', \'Project_id\': \'\', \'Feature_type\': \'\', \'Feature_name\': \'\', \'Calc_type\': \'\', \'Alarm_type\': \'\', \'Alarm_channel\': \'\', \'Int_param1\': \'\', \'Int_param2\': \'\', \'Owner\': [], \'Follower\': [] }]"}' feature_group_json = JSON.stringify(this.featureGroup).replace(/\"/g, "\\'"); //ajax请求webservice
$.ajax({
type: 'POST',
contentType: 'application/json;charset=utf-8',
url: 'your_url',
data: '{"featureGroupJson":"' + feature_group_json + '"}',
dataType: 'json',
success: function (data) {
alert("success");
}
});