0

私はJava開発者であり、初めて.netに取り組んでいます。YUIでJSONを使用しましたが、JQUERYを使用するのはこれが初めてです。を使用してJavaスクリプトオブジェクトをJSON文字列に変換JSON.stringify()し、コードビハインドで同じJSON文字列を取得していますが、.netオブジェクトに逆シリアル化しようとすると、整数であるプロパティの値を取得していますが、 Stringオブジェクトの値。

// クライアント側

$("#ButtonSave").click(function () {

    //convert gridview to JSON
    var jsonData = new Array();
    $.map($("table[id*=Gridview1] tr"), function (item, index) {
        if ($(item).find("input[type=text]").length > 0) {
            jsonData[index] = new Object();
            jsonData[index].charge = $(item).find("input[type=text][id*=txtCharge]").val();
            jsonData[index].produce = $(item).find("input[type=text][id*=txtProduce]").val();         
            jsonData[index].weight = $(item).find("input[type=text][id*=txtWeight]").val();
            jsonData[index].feet = $(item).find("input[type=text][id*=txtFeet]").val();
            jsonData[index].orderNumber = $(item).find("input[type=text][id*=txtOrderNumber]").val(); 
            jsonData[index].comments = $(item).find("input[type=text][id*=txtComments]").val();
        }
    });

    var jsonStringData = JSON.stringify(jsonData);

    var jqxhr = $.ajax({
        url: "Correction.aspx",
        type: "POST",
        timeout: 10000,
        data: "jsonData=" + jsonStringData
    })
    .error(function () {
        alert('Error');
    })
    .success(function (data) {
        alert('Success');
    });
});

//コードビハインド

 If Request.Form("jsonData") IsNot Nothing Then

        Dim cita As New TurnDetailVO
        Dim ser As New JavaScriptSerializer()
        Dim items As List(Of TurnDetailVO) = ser.Deserialize(Of List(Of TurnDetailVO))(Request.Form("jsonData"))

        items.RemoveAt(0)

        For Each cita In items
            Console.WriteLine(cita.CHARGE_ID, cita.PROD_ID)
        Next

 End If

//値オブジェクト

Imports Microsoft.VisualBasic
Imports System.Runtime.Serialization

Public Class TurnDetailVO

Private _CHARGE As String
Private _PROD As String
Private _WEIGHT As Integer
Private _FEET As Integer
Private _ORDER_NUMBER As String    
Private _COMMENTS As String


Public Sub New()

    _CHARGE = " "
    _PROD = " "
    _WEIGHT = 0 
    _FEET = 0
    _ORDER_NUMBER = " "
    _COMMENTS = " "

End Sub



Public Property CHARGE() As String
    Get
        Return _CHARGE
    End Get
    Set(ByVal value As String)
        _CHARGE = value
    End Set
End Property

Public Property PROD() As String
    Get
        Return _PROD
    End Get
    Set(ByVal value As String)
        _PROD = value
    End Set
End Property


Public Property WEIGHT() As Integer
    Get
        Return _WEIGHT
    End Get
    Set(ByVal value As Integer)
        _WEIGHT = value
    End Set
End Property


Public Property FEET() As Integer
    Get
        Return _FEET
    End Get
    Set(ByVal value As Integer)
        _FEET = value
    End Set
End Property

Public Property ORDER_NUMBER() As String
    Get
        Return _ORDER_NUMBER
    End Get
    Set(ByVal value As String)
        _ORDER_NUMBER = value
    End Set
End Property

Public Property COMMENTS() As String
    Get
        Return _COMMENTS
    End Get
    Set(ByVal value As String)
        _COMMENTS = value
    End Set
End Property



Public Function Clone() As TurnDetailVO
    Return DirectCast(Me.MemberwiseClone(), TurnDetailVO)
End Function

End Class

//JSON文字列

"[null,
{"charge":"T860243","produce":"S877020","weight":"13188","feet":"2898","orderNumber":"AN46270","comments":""},
{"charge":"T860243","produce":"S877021","weight":"13538","feet":"2978","orderNumber":"AN46270","comments":""},
{"charge":"T860243","produce":"S877022","weight":"30118","feet":"6618","orderNumber":"AN46270","comments":""},
{"charge":"T860243","produce":"S877023","weight":"23455","feet":"3345","orderNumber":"AN46270","comments":""}]"
4

1 に答える 1

0

2つのフィールド名が異なるため、逆シリアル化が期待どおりに動作していないようです。

プロパティ名PRODPRODUCEとに変更すると、機能ORDER_NUMBERするORDERNUMBERようになります。プライベートフィールド名はそのままにしておくことができます。変更する必要があるのはプロパティ名だけです。

于 2012-10-10T19:50:35.117 に答える