关于c#:json asp.net webservice调用错误

json asp.net webservice call error

我试图将一些ajax请求的信息发布到我用一些json数据写的webservice

以下是接收它的方法使用的C#参数

1
2
3
4
5
public bool AdvancedIWant(string WantTitle,
int WantCategory,
string WantBlogID,
float WantPrice,
string WantComments)

当我直接进入asmx控件并输入值时它工作正常所以它是我的json格式的东西我猜...
我使用firebug来查看ajax标题,我在帖子下得到了这个

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

这是在回应

{"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)

at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer
serializer, String input, Type type,
Int32 depthLimit)

at
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String
input)

at
System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext
context, JavaScriptSerializer
serializer)

at
System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData
methodData, HttpContext context)

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

我猜我的json格式无效? 我不确定也许我只是在凌晨2点错过了什么。


您的邮件服务器不应该像这样:

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

将上面与您的JSON进行比较。 我觉得你以错误的格式构建了你的JSON。

进一步注意WantBlog,在服务中你的参数是WantBlogId