Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserialize JSON in VB.net WebMethod
    text
    copied!<p>I have a JSON array built in javascript that I would like to pass into a VB.Net WebMethod and deserialize so I can loop over the items in the JSON array.</p> <p>Following is an example of the JSON. The JSON may have one or more items in it, in this case there are three items. I would like to deserialize these JSON arrays so I can loop over them in VB.Net. </p> <pre><code> 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" }]} </code></pre> <p>This is the javascript I use to pass the JSON into the WebMethod:</p> <pre><code> nameOfAsmx.deserializeJson(jsonArrayString) </code></pre> <p>This is what I have so far to try and deserialize the JSON. What I would like to do is loop over the items in the JSON and store them in some sort of object:</p> <pre><code> Public Function deserializeJson(jsonArrayString As String) As String Dim js As New System.Web.Script.Serialization.JavaScriptSerializer Dim rpts = js.Deserialize(Of rptsClass)(jsonArrayString) &lt;&lt;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 </code></pre> <p>Here is the class I built to store the JSON items so I can pass the values into other VB.Net functions;</p> <pre><code>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 </code></pre> <p>So my problem is that I can not figure out how to loop over the deserialized JSON and/or extract each item from the individual arrays. Any help would be appreciated.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload