I've been struggling with this problem for a couple of days now without any success. My goal is to deserialize a JSON object in VB.NET, but I keep encountering the following error:
"Type 'System.String' is not supported for deserialization of an array."
Despite trying all the solutions I could find, none seem to work.
Below is my JQuery code:
$.ajax({
type: "POST",
url: "/Services/Data_Services.asmx/AssignRoles",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ roleAssignments: roleassignments }),
datatype: "json",
success: function (data) {
alert("Group assignments successfully set");
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
This is the output: {"roleAssignments":[{"groupid":"2","role":"4","staffid":"111"},{"groupid":"2","role":"5","staffid":"999"},{"groupid":"2","role":"6","staffid":"999"},{"groupid":"2","role":"7","staffid":"0"},{"groupid":"2","role":"8","staffid":"999"},{"groupid":"2","role":"9","staffid":"15"}]}
(I have validated the JSON using JSONLint)
Here is the .NET code that throws an error during deserialization:
Public Function AssignRoles(ByVal roleAssignments As String) As String()
[.........]
Dim aRoleList As New List(Of roleAssignments)
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
aRoleList = js.Deserialize(Of List(Of roleAssignments))(roleAssignments)
[.........]
End Function
Public Class roleAssignments
Public Property groupid As String
Public Property role As String
Public Property staffid As String
End Class
Any suggestions on how to resolve this issue would be greatly appreciated. I have tried various approaches and consulted other examples, but I can't seem to figure out what's causing the problem.
Thank you.