【问题标题】:Sending array of data to PHP at server from vb.Net从 vb.Net 将数据数组发送到服务器上的 PHP
【发布时间】:2015-03-08 08:44:31
【问题描述】:

我什至不知道这是否可能,我不知道如何实现这一点。

我在 MS Access 数据库中有 50 条(可能更多)记录,我希望将它们发送到我的服务器上的 php file 以进行进一步处理。

到目前为止,我实现的是循环遍历记录并一一发送。这种需要时间的原因是网络问题,有些记录会发送,有些不会,每次发送的数据都必须等待服务器的报告才能发送下一个。

有没有一种方法可以一次发送所有记录,也许是在一个数组或其他东西中,并且能够在服务器端访问它?

下面是我的表架构。

--------------------------
|  id  |  phone  |  msg  |
--------------------------
|  1   | 09023023|  hi   |
|  2   | 09023024|  hey  |
|  3   | 09023025|  dear |  
--------------------------

谢谢

【问题讨论】:

  • 你可以使用Json..将结果转换成Json对象,一口气传下去
  • @TusharGupta 谢谢,能够使用您的建议解决此问题。

标签: php arrays json vb.net


【解决方案1】:

我找到了解决方案。我不知道这是否是最好的方法,但效果很好。

根据@Tushar Gupta 的建议,我使用位于http://www.newtonsoft.com/ 的第三方Json Library 创建了一个Json Array

我遍历数据库中的数据并将它们连接起来,如下所示:

代码

    Dim sms As New Sms 'note that this is a class
    Dim sms_obj As String = ""


    Try
        conn.Open()

        Dim cmd As OleDbCommand = New OleDbCommand("id, phone, msg FROM sms;", conn)

        Dim reader As OleDbDataReader = cmd.ExecuteReader


        'collate sms
        Dim i As Integer = 0
        While reader.Read()

            sms.id = reader("id").ToString()
            sms.member_phone = reader("phone").ToString()
            sms.member_message = reader("msg").ToString()


            If sms_obj = "" Then
                sms_obj = sms_obj + JsonConvert.SerializeObject(sms, Formatting.Indented)
            Else
                sms_obj = sms_obj + "," + JsonConvert.SerializeObject(sms, Formatting.Indented)
            End If

        End While

        sms_obj = "{ ""sms""" + ":" + "[" + sms_obj + "]}" ' this put the json string in an array

        'close the connection
        conn.Close()


        If sms.ToString <> "" Then
            HelperModule.SendSms(sms_obj)
        End If


        lblSmsState.Text = "sending sms done!"

    Catch ex As Exception
        msgbox(ex.toString())
        conn.Close()
    End Try

输出

    { "sms":[
          {
            "id": "1",
            "member_phone": "09023023",
            "member_message": "hi"
          },{
            "id": "2",
            "member_phone": "09023024",
            "member_message": "hey"
          },{
            "id": "3",
            "member-phone": "09023025",
            "member_message": "dear"
          }

        ]
      }

【讨论】:

    【解决方案2】:

    不确定您到底想达到什么目的,但您可以使用 MYSQL 或 phpmyAdmin

    您也可以在 excel 文件中在列顶部添加 $id = (,然后使用逗号分隔记录(CTRL + F 替换可能有用)并以 @ 结束列987654322@。您可能也希望对 phone 和 msg 执行相同的过程,然后将文件另存为 CSV 或将其设置为单行,或者将数据复制到文本编辑器中,然后将其保存为数组。

    php 还使用了多维数组,您可以读取它并将所有内容存储在一个数组中(不推荐,因为效率不高)。

    【讨论】:

      猜你喜欢
      • 2012-07-19
      • 2011-07-28
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      相关资源
      最近更新 更多