简体   繁体   English

json asp.net webservice调用错误

[英]json asp.net webservice call error

I am trying to post some info with an ajax request to a webservice I wrote with some json data我正在尝试通过 ajax 请求向我使用一些 json 数据编写的 Web 服务发布一些信息

Here are the C# parameters the method receiving it uses这里是C#参数接收方法使用

public bool AdvancedIWant(string WantTitle, 
int WantCategory, 
string WantBlogID, 
float WantPrice, 
string WantComments)

When I go to the asmx control directly and enter in the values it works fine so it is something with my json format I am guessing... I used firebug to look at the ajax headers and I got this under post当我将 go 直接输入到 asmx 控件并输入值时,它工作正常,所以它与我的 json 格式有关,我猜……我用萤火虫查看了 Z2705A83A5A0659CCE34583972637ED

JSON WantComments "sdfa" Source {"WantTitle": "sdfs"}, {"WantCategory": 1}, {"WantBlog": "FCA184D9-9F50-473F-922D-04E0EE004AB8"}, {"WantPrice": 5.55}, {"WantComments": "sdfa"} JSON WantComments "sdfa" Source {"WantTitle": "sdfs"}, {"WantCategory": 1}, {"WantBlog": "FCA184D9-9F50-473F-922D-04E0EE004AB8"}, {"WantPrice": 5}。 {“WantComments”:“sdfa”}

this under response这在回应中

{"Message":"Invalid JSON primitive: {\"WantCategory\": 1}, {\"WantBlog\": \"FCA184D9-9F50-473F-922D-04E0EE004AB8\"}, {\"WantPrice\": 5.55}, {\"WantComments\": \"sdfa\"}.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n {“消息”:“无效的 JSON 原语:{\“WantCategory\”:1},{\“WantBlog\”:\“FCA184D9-9F50-473F-922D-04E0EE004AB8\”},{\“WantPrice\”:5.55 }, {\"WantComments\": \"sdfa\"}.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串输入,Int32 depthLimit,JavaScriptSerializer 序列化程序)\r\n
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer 序列化程序,字符串输入,类型类型,Int32 depthLimit)\r\n 在 System.Web\r.Script.Serialization.JavaScript 输入) \n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext 上下文,JavaScriptSerializer 序列化程序)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParams 方法\r\nMethodHandler.GetRawParams 上下文)\r\nMethodHandler.GetRawParams 上下文
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

I am guessin my json format is invalid??我猜我的 json 格式无效?? I'm not sure maybe I am just missing something at 2 am.我不确定也许我只是在凌晨 2 点错过了一些东西。

Shouldn't your post to server be like this:你发给服务器的帖子不应该是这样的:

{"WantTitle": "sdfs", "WantCategory": 1, "WantBlog": "FCA184D9-9F50-473F-922D-04E0EE004AB8", "WantPrice": 5.55, "WantComments": "sdfa"}

Compare above with your JSON.将上述与您的 JSON 进行比较。 I feel you have constructed your JSON in wrong format.我觉得您的 JSON 格式错误。

Further watch out for WantBlog , in service your parameter says WantBlogId .进一步注意WantBlog ,在服务中你的参数说WantBlogId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM