如何从ASPX页面获取json字符串到VB.net函数Web服务 [英] How to get a json string from an ASPX page into a VB.net function web service

查看:45
本文介绍了如何从ASPX页面获取json字符串到VB.net函数Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASPX代码:

Datastr = JSON.stringify('{"data":{"Zip":"' + value1 + '","SKU":"' + value2 + '"}}');
            $.ajax({
                type:"POST",
                url:"http://webserver/Service1.asmx/GetCustomers",
                Data: Datastr,     
                contentType:"application/json; charset=utf-8",
                dataType:'json',
                timeout:30000,
                success: OnSuccess,
                failure:function(response){
                    alert(response.d);},
                error:function(response){
                    alert(response.d);}});


<VB.net 2015 code>

Public Function GetCustomers(DataStr) As List(Of Customer)

    Dim ZipTxt = ""
    Dim TxtSKU = ""
    Dim json As JObject = JObject.Parse(DataStr)

    ZipTxt = json.SelectToken("DataStr").SelectToken("Zip")
    TxtSKU = json.SelectToken("DataStr").SelectToken("SKU")


I am at a loss as to how to get the string generated in the Ajax script into the VB.net function.

我今天需要这个工作,并且需要2天后工作努力工作,取而代之的是。

I need this to work today and after 2 days of working on it, getting rather T'd off.

感谢您的帮助!







推荐答案

以下代码是我如何做的一个例子。

The following code is an example of how I do it.

    Public Shared Function GetMDBConfiguration() As DBConfiguration
        Dim client = New RestClient("https://api.themoviedb.org/3/configuration?api_key=MyAPIKey")
        Dim request = New RestRequest(Method.[GET])
        request.AddParameter("undefined", "{}", ParameterType.RequestBody)
        Dim response As IRestResponse = client.Execute(request)

        Dim json As String = response.Content
        Dim status As HttpStatusCode = response.StatusCode

        If status <> 200 Then
            Thread.Sleep(10000)
            response = client.Execute(request)
            json = response.Content
        End If

        Dim ser As JObject = JObject.Parse(json)
        Dim data As List(Of JToken) = ser.Children().ToList
        Dim output As String = ""
        Dim config = JsonConvert.DeserializeObject(Of DBConfiguration)(json)
        Return config
    End Function

你想要的下载用于将json转换为VB对象的NewtownSoft。

You would want to download NewtownSoft which is what is used for conversion of the json to VB objects.

要获取vb对象的定义,可以将json从调用复制到webservice到剪贴板,然后打开一个新的类文件,然后使用编辑/选择性粘贴让VS为你创建类。

To get the definition of the vb objects you can copy the json from the call to the webservice to the clipboard, then open a new class file, then use the Edit/Paste Special to have VS create the class(es) for you.


这篇关于如何从ASPX页面获取json字符串到VB.net函数Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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