我是AngularJS的初学者,我使用ASP.NET开发项目,允许提取xml内容文件并在Angularjs数据中显示。
我的C#代码是:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string publishMD(List<Dictionary<string, object>> childArray)
{
// Convertir le Dic en Json
string myJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(childArray);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\fatima.bouazza\Documents\XML\ff.txt"))
{
file.WriteLine(myJsonString);
}
//envoi à la fonction angularJS
');", true);
return myJsonString;
}
和AngularJS:
angular.module('myapp', []).controller('MyController', function ($scope, $http) {
var vm = this;
vm.mydata = [];
$http.get('mon-formulaire.aspx/publishMD').success(function (result) {
vm.myData = result.data;
console.log(result);
});
$http.Post('mon-formulaire.aspx/publishMD', { data: {} })
.success(function (data, status, headers, config) {
$scope.myData = data;
console.log(data);
})
.error(function (data, status, headers, config) {
console.log("error");
});
}).config(function ($httpProvider) {
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.post["Content-Type"] = "application/json; charset=utf-8";
});
我的AngularJS函数无法显示转换为JSON数组的XML内容。为什么会这样?我该如何解决?