我使用json返回數據的asp.net webservice,當我調用它時,它將數據返回給json,但將其嵌入到xml中。asp.net webservice返回JSON嵌入在XML ...?
我應該怎麼做在服務器端,以確保我的web服務僅返回JSON?
我的.asmx服務如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Text;
using System.Collections;
using System.IO;
using System.Xml;
[WebMethod(Description = "DemoMethod to get Total.")]
public string GetTotal(string a, string b, string c)
{
List<Hashtable> objMyclass = new List<Hashtable>();
JSonOutPutProperties jsonProperty = new JSonOutPutProperties();
//
int total = Convert.ToInt32(a) + Convert.ToInt32(b) + Convert.ToInt32(c);
jsonProperty.Properties.Add("Total", total);
objMyclass.Add(jsonProperty.Properties);
//
JsonOutput objjson = new JsonOutput();
objjson.objectcount = objMyclass.Count;
objjson.objectname = "Total";
objjson.objectvalues = objMyclass;
//
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(objjson);
return strJSON;
}
你能否澄清你的問題。例如,網址的結尾是什麼;你使用的是什麼樣的服務(asmx,svc)。你可以發佈你的web服務中返回json的方法的一部分嗎? – surfmuggle
你好threefouronesixonethree,發表更新的代碼,有任何想法是什麼問題 –
高鹿你能解決這個問題,通過添加行'[ScriptMethod(UseHttpGet = false,ResponseFormat = ResponseFormat.Json)]'? 添加屬性後的結果是什麼? – surfmuggle