The code I have to work with is Visual Basic. I have JSON that needs to be deserialized to an object.
I am running into the error:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type System.Collections.Generic.List1[AgentGroup] because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '[0].agentGroup.id', line 3, position 7
Now what I've done is instantiated the object, serialized it and write to a text file so that I can see how that data looks in JSON, which came out to this:
{
"agentGroup": [
{
"Id": 6873450,
"GroupName": "sig_latam_buenosaires",
"Fields": {
"Organization": "Football_Inc",
"LoadBalanced": "No",
"Description": "bye",
"TransferConcurrency": "",
"IsMxEnabled": false
}
},
{
"Id": 6873450,
"GroupName": "latam_buenosaires",
"Fields": {
"Organization": null,
"LoadBalanced": null,
"Description": null,
"TransferConcurrency": null,
"IsMxEnabled": false
}
},
{
"Id": 666,
"GroupName": "NY",
"Fields": {
"Organization": "TechniColor",
"LoadBalanced": "Yes",
"Description": "Hello World",
"TransferConcurrency": "",
"IsMxEnabled": true
}
}
]
}
But what the JSON I need to deserialize is in this format:
[{
"agentGroup": {
"id": 9943652,
"groupName": "technicolorBangalore",
"fields": {
"organization": "TechniColor",
"loadBalanced": "Yes",
"description": "Technicolor Bangalore Agents",
"mxEnabled": false,
"transferConcurrency": null
}
}
}, {
"agentGroup": {
"id": 6873450,
"groupName": "sig_latam_buenosaires",
"fields": {
"organization": "Viacom_Inc",
"loadBalanced": "No",
"description": "",
"mxEnabled": false,
"transferConcurrency": null
}
}
}]
I believe it has to do with the beginning square bracket [, I have searched on how to address this issue but being that the code is in Visual Basic, I have not found anything that helps. My code is:
Dim reader As New
StreamReader("C:\Users\poncek\Desktop\SigniantTextFile\AgentGroupList.txt")
Dim jsonString as String = reader.ReadToEnd
Dim works = JsonConvert.DeserializeObject(Of List(Of AgentGroupList))(jsonString)
But this is where the error occurs. I also see that when I write it to the text file my JSON looks different from what I need to deserialize. I am not sure what can be causing this
