I receive a JSON response in the following syntax, where it is returned as objects and not array. Is this right?
{
"status": "OK",
"product":
{
"name": "ABC",
"code": "A",
"Price": "2.5",
"active": true,
"contact":
{
"name": "X",
"phone": "999-999-9999",
"email": "X@company.com"
}
}
}
I use the following code to access it and it throws error. Object serialized to Object. JArray instance expected.
This code would work if the "product" was returned as an array.
Dim parsedObject = JObject.Parse(response)
Dim docs = JArray.FromObject(parsedObject("product")).Select(Function(x) x.ToObject(Of Product)())
Dim productDetail = docs.Select(Function(x) x).OrderBy(Function(x) x.name).ToList
Public Class Product
Public Property name As String
Public Property code As String
Public Property price As Decimal
Public Property active As Boolean
End Class
Do I need to access the JSON response differently or is the response syntax wrong?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.