The json looks like:
[
{Id:1, view,:true , write:false},
{Id:2, view: true , write:true}, ..etc
]
Imported Libraries:
Imports System.Web.Script.Serialization Imports System.IO
The Part of the code that will get the json from the request:
Dim tree_data As String = Nothing
HttpContext.Current.Request.InputStream.Position = 0
Using inputStream As StreamReader = New StreamReader(HttpContext.Current.Request.InputStream)
tree_data = inputStream.ReadToEnd()
End Using
Dim jsonSerializer As System.Web.Script.Serialization.JavaScriptSerializer =
New System.Web.Script.Serialization.JavaScriptSerializer()
Dim permissions = jsonSerializer.Deserialize(Of List(Of Object))(tree_data)
The Part of the code that parsing the json to extract values, and may be this piece of code can be written in a different way but that’s what I used:
For Each obj In permissions
Dim id As Integer
Dim view As Boolean
Dim write As Boolean
For Each pair In obj // each object is a pair of key and value
If pair.Key.Equals("Id") Then
id = pair.Value
ElseIf pair.Key.Equals("view") Then
view = pair.Value
ElseIf pair.Key.Equals("write") Then
write = pair.Value
End If
Next
// Do something with the current id , view ,write parameters
Next
