0
我使用这个代码json响应正确吗?
public static string myjson(bool a)
{
if (a == true)
{
RootObject o = new RootObject();
o.success = "true";
o.firstname = "anurag";
o.usertype = "admin";
o.userid = "123";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string d=serializer.Serialize(o);
return d;
}
else
{
errormessage o = new errormessage();
o.success = "false";
o.message = "invalid username or password";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string p=serializer.Serialize(o);
return p.ToString();
}
}
当我主持我的web服务IIS和多余的这项服务,我得到响应
{"checkuserResult":" {\"success\":\"true\",\"firstname\":\"anurag\",\"userid\":\"123\",\"usertype\":\"admin\"}"}
我想作为回报什么是公正的JSON响应
{"success":"true","firstname":"anurag","userid":"123","usertype":"admin"}
请帮忙?
看起来你错过了将json字符串返回给客户端的代码。该错误可能在那里。 – 2014-09-25 04:42:22
@ user3771185 \“他们是逃避字符,如果你在调试模式下查看它显示,但输出是有效的json。, – 2014-09-25 05:10:00
@ user3771185更改操作合同中的'BodyStyle = WebMessageBodyStyle.Bare' - WCF – 2014-09-25 05:22:03