【问题标题】:How to get data of webservice by json format?如何通过json格式获取webservice的数据?
【发布时间】:2019-02-06 18:40:22
【问题描述】:

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

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:

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

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

如何做到这一点?

【问题讨论】:

    标签: json vb.net web-services


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

      我用这个 ajax 解决了

       $.ajax({
              type: "POST",
              url: "/WebService.asmx/GetAllRss",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
             success: function (result) {
                  console.log(result);
              }
          });
      

      【讨论】:

        猜你喜欢
        • 2011-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-19
        • 2013-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多