相关疑难解决方法(0)

Jquery Ajax将json发布到webservice

我试图将一个JSON对象发布到asp.net webservice.

我的json看起来像这样:

var markers = { "markers": [
  { "position": "128.3657142857143", "markerPosition": "7" },
  { "position": "235.1944023323615", "markerPosition": "19" },
  { "position": "42.5978231292517", "markerPosition": "-3" }
]};
Run Code Online (Sandbox Code Playgroud)

我使用json2.js来串行我的json对象.

我正在使用jquery将其发布到我的webservice.

  $.ajax({
        type: "POST",
        url: "/webservices/PodcastService.asmx/CreateMarkers",
        data: markers,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data){alert(data);},
        failure: function(errMsg) {
            alert(errMsg);
        }
  });
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

"无效的JSON原语:

我发现了一堆与此相关的帖子,这似乎是一个非常常见的问题,但我没有尝试解决这个问题.

当firebug发布到服务器的内容时​​,它看起来像这样:

标记%5B0%5D%5Bposition%5D = 128.3657142857143&标记%5B0%5D%5BmarkerPosition%5D = 7&标记%5B1%5D%5Bposition%5D = 235.1944023323615&标记%5B1%5D%5BmarkerPosition%5D = 19&标记%5B2%5D%5Bposition% 5D = 42.5978231292517&标记%5B2%5D%5BmarkerPosition%5D = -3

我正在调用的webservice函数是:

[WebMethod]
public string CreateMarkers(string markerArray)
{
    return "received markers";
}
Run Code Online (Sandbox Code Playgroud)

ajax jquery json web-services

228
推荐指数
3
解决办法
48万
查看次数

JSON的WCF REST POST:参数为空

使用Fiddler我将JSON消息发布到我的WCF服务.该服务使用System.ServiceModel.Activation.WebServiceHostFactory

[OperationContract]
[WebInvoke
(UriTemplate = "/authenticate",
       Method = "POST",
       ResponseFormat = WebMessageFormat.Json,
       BodyStyle = WebMessageBodyStyle.WrappedRequest
       )]
String Authorise(String usernamePasswordJson);
Run Code Online (Sandbox Code Playgroud)

进行POST后,我可以进入代码,但参数usernamePasswordJsonnull.为什么是这样?

注意:当我将BodyStyle设置为Bare时,该帖子甚至没有找到我调试的代码.

这是小提琴画面: 在此输入图像描述

wcf json fiddler

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

json ×2

ajax ×1

fiddler ×1

jquery ×1

wcf ×1

web-services ×1