我正在用asp.net创建一个webservice服务。下面是我得到的回复。
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">{"Question1":"do the like the idea of the first speaker?","Option1":"YES","Option2":"NO","Option3":"NOT SURE","Option4":"","Option5":"","Type":"button","QID":"q1"}</string>[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetQuestions()
{
return new JavaScriptSerializer().Serialize(Biz.BAL.GetQuestions());
}发布于 2015-01-01 12:40:57
请在Web方法中使用以下行:
JavaScriptSerializer Machinejson = new JavaScriptSerializer();
this.Context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
this.Context.Response.ContentType = "application/json; charset=utf-8"; // to remove xml tag from response
this.Context.Response.Write(Machinejson.Serialize([Object or string to return in form of json)]));https://stackoverflow.com/questions/12705380
复制相似问题