首页 > 解决方案 > 如何通过json格式获取webservice的数据?

问题描述

我尝试通过 json 格式获取我的网络服务的数据,如下所示:

Imports System.Web
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols


' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()>
<WebService(Namespace:="http://tempuri.org/")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Public Class WebService
    Inherits System.Web.Services.WebService

    <WebMethod()>
    Public Function GetAllRss() As List(Of Rss)
        Dim db As EMCEntities1 = New EMCEntities1()
        Dim RssList As List(Of Rss) = db.Rss.ToList()
        Return RssList
    End Function

End Class

阿贾克斯:

$.ajax({
        type: "POST",
        url: "/WebService.asmx/GetAllRss",
       success: function (result) {
            console.log(result);
        }
    });

在这种情况下,我通过 XML 格式获取数据?

这个怎么做?

标签: jsonvb.netweb-services

解决方案


Web 服务需要返回编码为 JSON 的数据,或者您可以使用jQuery.parseXML()解析 XML 响应。

可能有一种方法可以使用“json2xml”之类的库将 json 转换为 XML。

这可能会有所帮助: https ://goessner.net/download/prj/jsonxml/

有关 XML 和 JSON 转换的其他信息: https ://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html


推荐阅读