0

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.

asked May 28, 2011 at 6:06

1 Answer 1

1

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.

answered May 28, 2011 at 6:20
Sign up to request clarification or add additional context in comments.

1 Comment

that totally fixed it thank you very much! I can sleep now :D

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.