vue數據源轉json問題


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM