从vb.net端到asp.net的json字符串

时间:2021-08-31 13:58:57

How would I get my JSON string to my asp.net using jquery I am confused about using web methods or arrays or functions all the examples i have seen are in C#. All i want is to take the json string parse it.

如何使用jquery将我的JSON字符串传递给我的asp.net我对使用Web方法或数组或函数感到困惑我在C#中看到的所有示例都是如此。我想要的就是让json字符串解析它。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    cmd.Connection = conn
    conn.Open()
    Dim ds As New DataSet
    cmd.CommandText = "MY SELECT STATEMENT IS IN HERE(DIDNT WANT TO POST ONLINE)"
    da.Fill(ds)
    da.FillSchema(ds, SchemaType.Mapped)
    Dim myObject = ds.GetXml
    Dim jsonString = New JavaScriptSerializer().Serialize(myObject)
   conn.Close()
End Sub

I want to take either the jsonstring or myobject to the server side. jsonstring is json and myobject is xml. That way I can create a table client side that will include math functions. I am very new at this so I would need a clear explanation and maybe even an example. I have read about pagemethods and I have tried using this example on calling server side functions example

我想把jsonstring或myobject带到服务器端。 jsonstring是json,myobject是xml。这样我就可以创建一个包含数学函数的表客户端。我对此很新,所以我需要一个明确的解释,甚至可能是一个例子。我已经阅读过有关页面方法的内容,我尝试在调用服务器端函数示例时使用此示例

Or can you tell me a simple way to go from sql to ajax. What is the best method for placing large datasets on a asp.net page without using paging.

或者你能告诉我一个从sql到ajax的简单方法吗?在不使用分页的情况下,在asp.net页面上放置大型数据集的最佳方法是什么。

I am basically rewriting an asp page that they use now to use ajax, because it loads to slow, heres an example of the current asp code and what I am trying to achieve.

我基本上重写了他们现在用来使用ajax的asp页面,因为它加载速度慢,这是当前asp代码的一个例子以及我想要实现的目标。

                response.write("<tr><td>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("book7"))
            response.write("</td><td>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("dep7"))
            response.write("</td><td>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("lead"))
            response.write("</td><td>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("hear"))
            response.write("</td><td>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("cname"))
            response.write("</td><td>")

%><font face="Arial,Helvetica,sans-serif" size="-2"><%


response.write(rscontest.fields.item("theme") & " - " & rscontest.fields.item("tour"))
            response.write("</td><td align='right'>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("userid"))
            response.write("</td><td align='right'>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            response.write(rscontest.fields.item("pax_count"))
            pax = pax + rscontest.fields.item("pax_count")
            response.write("</td><td align='right'>")

            %><font face="Arial,Helvetica,sans-serif" size="-2"><%
            IF rscontest.fields.item("status") = "XL" then
                response.write(formatnumber(rscontest.fields.item("CXVALUE"),2))
                sales = sales - formatnumber(rscontest.fields.item("CXVALUE"),2)
            ELSE
                response.write(formatnumber(rscontest.fields.item("AMOUNT"),2))
                sales = sales + formatnumber(rscontest.fields.item("AMOUNT"),2)
            END IF

        response.write("<tr><td rowspan=1>")    
        %><font face="Arial,Helvetica,sans-serif" size="-2"></style><%
            response.write(rscontest.fields.item("description"))




            rscontest.movenext

        wend

anything it is writing is from an sql statement, and it uses a running total.

它写的任何东西都来自一个sql语句,它使用一个运行总计。

3 个解决方案

#1


2  

First, read this SO thread, if it doesn't help - read on.

首先,阅读这个SO线程,如果它没有帮助 - 请继续阅读。

I'm not sure why you want to pass the json around after you get if from the webservice, but the following steps should get you there:

我不确定你为什么要在从webservice获得后传递json,但是以下步骤应该让你到达:

  1. Create a webservice (start with a default HelloWorld service from the template)
  2. 创建一个webservice(从模板中的默认HelloWorld服务开始)

  3. Call the webservice from javasscript (jQuery's $.ajax() does just that)
  4. 从javasscript调用webservice(jQuery的$ .ajax()就是这样)

  5. Assign the xml (json) that you get from the webservice to a hidden field (use asp:HiddenField to make sure it's available on the server)
  6. 将从Web服务获取的xml(json)分配给隐藏字段(使用asp:HiddenField确保它在服务器上可用)

  7. In your code behind - get the value of the hidden field, and do what you have to do with it.
  8. 在你的代码背后 - 获取隐藏字段的值,并做你必须做的事情。

You should really rephrase your question, and tell us what the ultimate goal is. When you say "I want to build a table", that doesn't mean anything.

您应该重新解释您的问题,并告诉我们最终目标是什么。当你说“我想建一张桌子”时,这并不意味着什么。

#2


1  

In your Body tag in ASP.NET put an onload attribute that calls a Javascript function that makes the Ajax call (you can use JQuery or do it manually (just don't forget to put a ServiceReference in your ScriptManager) to a web service method. The return method (in javascript) will then have to parse the JSON. If you're going to build the tables on the server side there is no point in serializing the object into JSON.

在ASP.NET的Body标签中放置一个onload属性,该属性调用一个调用Ajax调用的Javascript函数(您可以使用JQuery或手动执行它(只是不要忘记在您的ScriptManager中放置ServiceReference)到Web服务方法返回方法(在javascript中)将必须解析JSON。如果你要在服务器端构建表,那么将对象序列化为JSON是没有意义的。

#3


1  

I have a large dataset, so wouldn't using the json and ajax make my page load faster, rather than using sql. Also the reason is I want to format my information using html and tables. Is this the right direction?

我有一个大型数据集,所以不会使用json和ajax使我的页面加载速度更快,而不是使用sql。另外原因是我想使用html和表格格式化我的信息。这是正确的方向吗?

Whether you pull the data from a web service call on the client or server side you are still loading it through a web service that has to retrieve it from some back end data store (i.e. SQL). Using a client side approach (JSON) will make the delivery of the page quicker but the user will still wait for the overall load which the data is being delivered to the client.

无论是从客户端还是服务器端的Web服务调用中提取数据,您仍然通过必须从某些后端数据存储(即SQL)检索它的Web服务加载它。使用客户端方法(JSON)将使页面的传递更快,但用户仍将等待将数据传递到客户端的总体负载。

From a performance stand point you would probably want to look into LINQ to deliver only the page of data that you need (i.e. There are 5,000 records and the user is only viewing the first 100 on Page 1, so only return Page 1). Its a pit fall alot of new developers fall into and is a bit complex but you seem to have the appetite for it. Good luck.

从性能角度来看,您可能希望查看LINQ以仅提供您需要的数据页(即,有5,000条记录,而用户仅查看第1页上的前100条,因此只返回第1页)。它的陷阱有很多新的开发人员陷入困境并且有点复杂,但你似乎对它有胃口。祝你好运。

#1


2  

First, read this SO thread, if it doesn't help - read on.

首先,阅读这个SO线程,如果它没有帮助 - 请继续阅读。

I'm not sure why you want to pass the json around after you get if from the webservice, but the following steps should get you there:

我不确定你为什么要在从webservice获得后传递json,但是以下步骤应该让你到达:

  1. Create a webservice (start with a default HelloWorld service from the template)
  2. 创建一个webservice(从模板中的默认HelloWorld服务开始)

  3. Call the webservice from javasscript (jQuery's $.ajax() does just that)
  4. 从javasscript调用webservice(jQuery的$ .ajax()就是这样)

  5. Assign the xml (json) that you get from the webservice to a hidden field (use asp:HiddenField to make sure it's available on the server)
  6. 将从Web服务获取的xml(json)分配给隐藏字段(使用asp:HiddenField确保它在服务器上可用)

  7. In your code behind - get the value of the hidden field, and do what you have to do with it.
  8. 在你的代码背后 - 获取隐藏字段的值,并做你必须做的事情。

You should really rephrase your question, and tell us what the ultimate goal is. When you say "I want to build a table", that doesn't mean anything.

您应该重新解释您的问题,并告诉我们最终目标是什么。当你说“我想建一张桌子”时,这并不意味着什么。

#2


1  

In your Body tag in ASP.NET put an onload attribute that calls a Javascript function that makes the Ajax call (you can use JQuery or do it manually (just don't forget to put a ServiceReference in your ScriptManager) to a web service method. The return method (in javascript) will then have to parse the JSON. If you're going to build the tables on the server side there is no point in serializing the object into JSON.

在ASP.NET的Body标签中放置一个onload属性,该属性调用一个调用Ajax调用的Javascript函数(您可以使用JQuery或手动执行它(只是不要忘记在您的ScriptManager中放置ServiceReference)到Web服务方法返回方法(在javascript中)将必须解析JSON。如果你要在服务器端构建表,那么将对象序列化为JSON是没有意义的。

#3


1  

I have a large dataset, so wouldn't using the json and ajax make my page load faster, rather than using sql. Also the reason is I want to format my information using html and tables. Is this the right direction?

我有一个大型数据集,所以不会使用json和ajax使我的页面加载速度更快,而不是使用sql。另外原因是我想使用html和表格格式化我的信息。这是正确的方向吗?

Whether you pull the data from a web service call on the client or server side you are still loading it through a web service that has to retrieve it from some back end data store (i.e. SQL). Using a client side approach (JSON) will make the delivery of the page quicker but the user will still wait for the overall load which the data is being delivered to the client.

无论是从客户端还是服务器端的Web服务调用中提取数据,您仍然通过必须从某些后端数据存储(即SQL)检索它的Web服务加载它。使用客户端方法(JSON)将使页面的传递更快,但用户仍将等待将数据传递到客户端的总体负载。

From a performance stand point you would probably want to look into LINQ to deliver only the page of data that you need (i.e. There are 5,000 records and the user is only viewing the first 100 on Page 1, so only return Page 1). Its a pit fall alot of new developers fall into and is a bit complex but you seem to have the appetite for it. Good luck.

从性能角度来看,您可能希望查看LINQ以仅提供您需要的数据页(即,有5,000条记录,而用户仅查看第1页上的前100条,因此只返回第1页)。它的陷阱有很多新的开发人员陷入困境并且有点复杂,但你似乎对它有胃口。祝你好运。