Ajax VB Json字符串

时间:2017-04-19 19:14:52

标签: asp.net json ajax vb.net webmethod

我很难找到适用于此实例的Visual Basic Json字符串。我一直收到错误消息状态" of" [object Object]"。

我和C#一起使用了#34; \""在Json代码中但VB并不那么容易。

Default.aspx的

<script type="text/javascript" src="~/jquery=1.10.2.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%= Button1.ClientID %>").click(function () {
            var mo1 = $("#<%= TextBox1.ClientID %>").val();
            var dy1 = $("#<%= TextBox2.ClientID %>").val();
            var yr1 = $("#<%= TextBox3.ClientID %>").val();
            var data = { mo: mo1, dy: dy1, yr: yr1 };
            var json1 = JSON.stringify(data); 
            $.ajax
            ({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: json1,
                url: "Default.aspx/GetDate",
                success: function (result) {
                    $("#<%= TextBox4.ClientID %>").val(result.d);
                    $("#<%= Button2.ClientID %>").trigger(click);
                },
                    error: function (status, ex) {
                    alert("Error Code: Status: " + status + " Ex: " + ex);
                }
            });
            return false;
        });
    });
</script>

Default.aspx.vb

<System.Web.Services.WebMethod> Public Shared Function GetDate(ByVal mo As Integer, ByVal dy As Integer, ByVal yr As Integer) As String
    ...

    json1 = "[{""id"":""100"",""datetime"":""04/10/2017"",""col1"":""1"",""col2"":""2"",""col3"":""3""}]"
    Dim jsonout As String = JsonConvert.SerializeObject(json1)
    Return jsonout
End Function

我试过别人:

            'json1 = "[{" & Chr(34) & "id" & Chr(34) & ":" & Chr(34) & dataa(i, 1) & Chr(34) & "," & Chr(34) & "datetime" & Chr(34) & ":" & Chr(34) & dataa(i, 2) & Chr(34) & "," & Chr(34) & "col1" & Chr(34) & ":" & Chr(34) & dataa(i, 3) & Chr(34) & "," & Chr(34) & "col2" & Chr(34) & ":" & Chr(34) & dataa(i, 4) & Chr(34) & "," & Chr(34) & "col3" & Chr(34) & ":" & Chr(34) & dataa(i, 5) & Chr(34) & "}]"
            'json1 = "[{""id"":""" & dataa(i, 1) & """,""datetime"":""" & dataa(i, 2) & """,""col1"":""" & dataa(i, 3) & """,""col2"":""" & dataa(i, 4) & """col3"","":""" & dataa(i, 5) & """}]"
            'json1 = "[{" & """id"":"" & dataa(i, 1) & "",""datetime"":"" & dataa(i, 2) & ""col1"":"" & dataa(i, 3) & "",""col2"":"" & dataa(i, 4) & "",""col3"":"" & dataa(i, 5) & ""}]"
            'json1 = "[{" & """id""" & ":""" & dataa(i, 1) & """," & """datetime""" & ":""" & dataa(i, 2) & """," & """col1""" & ":""" & dataa(i, 3) & """," & """col2""" & ":""" & dataa(i, 4) & """," & """col3""" & ":""" & dataa(i, 5) & """}]"
            'json1 = "[{" & """ & "id" & """ & ":" & """ & "100" & """ & "," & """ & "datetime" & """ & ":" & """ & "04/10/2017" & """ & "," & """ & "col1" & """ & ":" & """ & "1" & """ & "," & """ & "col2" & """ & ":" & """ & "2" & """ & "," & """ & "col3" & """ & ":" & """ & "3" & """ & "}]"

Class.vb

Public Class datapart
Public Property id() As Integer
    Get
        Return m_id
    End Get
    Set(value As Integer)
        m_id = value
    End Set
End Property
Private m_id As Integer
Public Property datetime() As String
    Get
        Return m_datetime
    End Get
    Set(value As String)
        m_datetime = value
    End Set
End Property
Private m_datetime As String
Public Property col1() As Integer
    Get
        Return m_col1
    End Get
    Set(value As Integer)
        m_col1 = value
    End Set
End Property
Private m_col1 As Integer
Public Property col2() As Integer
    Get
        Return m_col2
    End Get
    Set(value As Integer)
        m_col2 = value
    End Set
End Property
Private m_col2 As Integer
Public Property col3() As Integer
    Get
        Return m_col3
    End Get
    Set(value As Integer)
        m_col3 = value
    End Set
End Property
Private m_col3 As Integer
End Class

0 个答案:

没有答案