如何从ASP.NET的.asmx返回JSON? [英] How to return JSON from ASP.NET .asmx?

查看:746
本文介绍了如何从ASP.NET的.asmx返回JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的测试方法:

Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols


<WebService(Namespace:="http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

Public Class DemoService
 Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetCustomer() As String
    Return "Microsoft"
End Function


End Class

即使有ResponseFormat属性添加的反应仍然被作为XML返回,而不是JSON。

Even with the ResponseFormat attribute added the response is still being returned as XML rather than JSON.

思想AP preciated。

Thoughts appreciated.

推荐答案

你有.NET 3.5或更高版本安装?

Do you have .NET 3.5 or greater installed?

<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptserviceattribute.aspx\"相对=nofollow> ScriptServiceAttribute 是在.NET 3.5和4.0。

ScriptServiceAttribute is in .NET 3.5 and 4.0.

此外,清除你的ASP.NET临时文件,动态代理可以被缓存。

Also, clear your ASP.NET temp files, the dynamic proxy could be cached.

这篇关于如何从ASP.NET的.asmx返回JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆