开发者

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

Here are the C# parameters the method receiving it uses

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

JSON WantComments "开发者_开发技巧sdfa" Source {"WantTitle": "sdfs"}, {"WantCategory": 1}, {"WantBlog": "FCA184D9-9F50-473F-922D-04E0EE004AB8"}, {"WantPrice": 5.55}, {"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

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

at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

I am guessin my json format is invalid?? I'm not sure maybe I am just missing something at 2 am.


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. I feel you have constructed your JSON in wrong format.

Further watch out for WantBlog, in service your parameter says WantBlogId.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜