開發過程中使用到了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");
}
});