asp.net Web服务返回嵌入在xml中的json。。。?

asp.net Web服务返回嵌入在xml中的json。。。?,asp.net,xml,json,web-services,Asp.net,Xml,Json,Web Services,我使用asp.NETWebService和json返回数据,当我调用它时,它以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; usi

我使用asp.NETWebService和json返回数据,当我调用它时,它以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;
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Services;
使用System.Web.Script.Services;
使用System.Web.Script.Serialization;
使用系统文本;
使用系统集合;
使用System.IO;
使用System.Xml;
[WebMethod(Description=“DemoMethod以获取总计。”)]
公共字符串GetTotal(字符串a、字符串b、字符串c)
{
List objMyclass=新列表();
JSonOutPutProperties jsonProperty=新的JSonOutPutProperties();
// 
int total=Convert.ToInt32(a)+Convert.ToInt32(b)+Convert.ToInt32(c);
jsonProperty.Properties.Add(“Total”,Total);
添加(jsonProperty.Properties);
//
JsonOutput objjson=新的JsonOutput();
objjson.objectcount=objMyclass.Count;
objjson.objectname=“总计”;
objjson.objectvalues=objMyclass;
//
JavaScriptSerializer js=新的JavaScriptSerializer();
字符串strJSON=js.Serialize(objjson);
返回strJSON;
}

如果在方法中添加以下行,问题可能会得到解决:

[WebMethod(Description = "DemoMethod to get Total.")]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public string GetTotal(string a, string b, string c)
{
    ...
您可能必须确保您正在使用。斯科特·古思里


请看一下下面的问题或那篇文章中的答案。我有过一次。

你能澄清一下你的问题吗。例如,url的结尾是什么;您使用的是哪种服务(asmx、svc)。您能从您的Web服务发布返回json的方法的一部分吗?您好threefouronesixonethree,用代码更新了post,您知道什么是错误的吗?您能通过添加行
[ScriptMethod(UseHttpGet=false,ResponseFormat=ResponseFormat.json)]
来解决问题吗?添加属性后的结果是什么?能否提供更多信息。您是否调试过objjson、jsonProperty和objMyclass。谁在呼叫谁:在屏幕截图中,您打开了一个浏览器,因此我假设您可以通过在浏览器中输入url来访问您的服务。如果在另一个浏览器中打开它,它会是什么样子;调用该方法的url是什么,等等。如果没有更多的信息,这就是在黑暗中没有鱼竿捕鱼。