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