$ http.post后退错了JSON [英] $http.post retrun wrong JSON

查看:77
本文介绍了$ http.post后退错了JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

客户端:

Hi all,
Client Side:

------------
API.getDetails = function (id) {

        return $http.post("webservices/WebService1.asmx/getDetails"
       ,JSON.stringify({ 'm': { id: "123"} })
        
        )
    }
---------

      APIservice.getDetails($scope.id).then(function (data, status, headers, config) {
          console.log(data.data);
          $scope.details = data.data;

      },
      function (data) { console.log(data); alert(data); }

      );



服务器端:


Server Side:

                [WebMethod]
[ScriptMethod( UseHttpGet=false, ResponseFormat = ResponseFormat.Json)]
public void getDetails(lst m)
{
    try
    {
        List<Volumes> l = new List<Volumes>();
        l.Add(new Volumes { name= "TEST123", options = "10", shares = "10", stocks = "10", tickets = "10" });

        JavaScriptSerializer js = new JavaScriptSerializer();
        Context.Response.Clear();
        Context.Response.ContentType = "application/json;charset=utf-8";

       Context.Response.Write(js.Serialize(l));
    }
    catch (Exception ex) { throw ex; }
}





当我调用getDetails方法然后方法调用成功并且js.Serialize(l)创建正确的json但在客户端

angular.js





when I call the getDetails method then method call successfully and js.Serialize(l) create correct json but the on client side
angular.js

function fromJson(json) {
  return isString(json)
      ? JSON.parse(json)
      : json;
}





其中json有额外{d:null} !!!!!!!!



where json has extra {d:null} !!!!!!!!

"[{"mpid":"TEST123","shares":"10","stocks":"10","options":"10","tickets":"10"}]{"d":null}"







但是当我删除




but when I remove the ,

JSON.stringify({ 'm': { id: "123"} })



and

lst m

然后没有错误显示。但我也希望传递param。





你能告诉我哪里有问题吗?



谢谢大家,

then no error show. But i want pass param as well.


can you tell me where is issue?

Thanks all,

推荐答案

http.post(webservices / WebService1.asmx / getDetails
,JSON.stringify({' m':{id:123}})


}
---------

APIservice.getDetails (
http.post("webservices/WebService1.asmx/getDetails" ,JSON.stringify({ 'm': { id: "123"} }) ) } --------- APIservice.getDetails(


scope.id).then(function(data,status,headers,config){
console.log(data.data);
scope.id).then(function (data, status, headers, config) { console.log(data.data);


scope.details = data.data;

},
function(data){console.log(data); alert(data);}

);
scope.details = data.data; }, function (data) { console.log(data); alert(data); } );



服务器端:


Server Side:

                [WebMethod]
[ScriptMethod( UseHttpGet=false, ResponseFormat = ResponseFormat.Json)]
public void getDetails(lst m)
{
    try
    {
        List<Volumes> l = new List<Volumes>();
        l.Add(new Volumes { name= "TEST123", options = "10", shares = "10", stocks = "10", tickets = "10" });

        JavaScriptSerializer js = new JavaScriptSerializer();
        Context.Response.Clear();
        Context.Response.ContentType = "application/json;charset=utf-8";

       Context.Response.Write(js.Serialize(l));
    }
    catch (Exception ex) { throw ex; }
}





当我调用getDetails方法然后方法调用成功并且js.Serialize(l)创建正确的json但在客户端

angular.js





when I call the getDetails method then method call successfully and js.Serialize(l) create correct json but the on client side
angular.js

function fromJson(json) {
  return isString(json)
      ? JSON.parse(json)
      : json;
}





其中json有额外{d:null} !!!!!!!!



where json has extra {d:null} !!!!!!!!

"[{"mpid":"TEST123","shares":"10","stocks":"10","options":"10","tickets":"10"}]{"d":null}"







但是当我删除




but when I remove the ,

JSON.stringify({ 'm': { id: "123"} })



and

lst m

然后没有错误显示。但我也希望传递param。





你能告诉我哪里有问题吗?



全部谢谢,

then no error show. But i want pass param as well.


can you tell me where is issue?

Thanks all,


这篇关于$ http.post后退错了JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆