在VB.net WebMethod中反序列化JSON

时间:2013-11-26 02:16:12

标签: javascript json vb.net deserialization

我有一个用javascript构建的JSON数组,我希望将其传递给VB.Net WebMethod并反序列化,这样我就可以遍历JSON数组中的项目。

以下是JSON的示例。 JSON中可能包含一个或多个项目,在这种情况下有三个项目。我想反序列化这些JSON数组,以便我可以在VB.Net中循环它们。

 jsonArrayString =   { "reportArray": [{ "reportName":"volumeSST",  "reportQuarter":"9/30/2013" , "dateTime":"1385430869676" , "muLevel":"false" , "cumulative":"false" ,
    "perAcre":"perAcreFalse" , "reportLevel":"TRACT" , "qryFeature":"11000110000000" },
    { "reportName":"volumeSST",  "reportQuarter":"9/30/2013" , "dateTime":"1385430869676" ,
    "muLevel":"false" , "cumulative":"false" , "perAcre":"perAcreFalse" , 
    "reportLevel":"TRACT" , "qryFeature":"11000180000000" }, { "reportName":"volumeSST", 
    "reportQuarter":"9/30/2013" , "dateTime":"1385430869676" , "muLevel":"false" , 
    "cumulative":"false" , "perAcre":"perAcreFalse" , "reportLevel":"TRACT" , 
    "qryFeature":"11000190000000" }]}

这是我用来将JSON传递给WebMethod的JavaScript:

 nameOfAsmx.deserializeJson(jsonArrayString)

这是我到目前为止尝试反序列化JSON的方法。我想要做的是循环JSON中的项目并将它们存储在某种对象中:

 Public Function deserializeJson(jsonArrayString As String) As String
        Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
        Dim rpts = js.Deserialize(Of rptsClass)(jsonArrayString) <<I am not sure if this is correct.

        'NEED SOME CODE TO LOOP OVER rpts AND GET THE ITEMS (i.e. reportName, report Quarter etc.)

    End Function

这是我为存储JSON项而构建的类,因此我可以将值传递给其他VB.Net函数;

Public Class rptsClass
    Public reportName As String
    Public reportQuarter As String
    Public dateTime As String
    Public muLevel As String
    Public cumulative As String
    Public perAcre As String
    Public reportLevel As String
    Public qryFeature As String
End Class

所以我的问题是我无法弄清楚如何循环反序列化的JSON和/或从各个数组中提取每个项目。任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案