开发者

Issue in .Net JSON based Web service

开发者 https://www.devze.com 2023-04-03 21:42 出处:网络
I am developing a ASP .Net Web service. I want the data in JSON format. But I am getting only partial results.

I am developing a ASP .Net Web service. I want the data in JSON format.

But I am getting only partial results.

This is about the environment.

Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM Microsoft .NET Framework Version 3.5

Installed Edition: Professional

I have included the following in my code.

using System.Web.Script.Services;
using System.Web.Script.Serialization;

This is the method I am using:

[WebMethod(EnableSession = true)]

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getDeviceTo开发者_C百科kens()
{

    ArrayList list = (ArrayList)Session["Session"];
    //String s =(String) Session["Session"];
    return new JavaScriptSerializer().Serialize(list);

}

The result I am getting is:

<string>["one","two"]</string>

I need the response as

["one","two"] What is the problem here?

Is there any other setting I need to do?

UPDATE:

The output I am getting is <string>["one","two"]</string>


I've tried to test your problem on local web service included in same project as class from which I am calling this web service and everything works fine. I am getting output without

<string></string>.

I am also using something like this on more complex data and everything works fine (even when calling this service from ajax)


I used this to get the output as Json, try
ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json

0

精彩评论

暂无评论...
验证码 换一张
取 消