Deserialise JSON from a solar inverter API - json

I have JSON data from a Fronius solar inverter. I'm trying to read it into VB.NET classes so I can then work some other magic on it (add to a DB, use the info to control household devices etc).
I've parsed the JSON through some online resource that all say it's ok.
When running my code the classes are coming back as nothing.
Here's the base code for deserializing:
Dim fileReader As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\Temp\JsonCrap.js")
Dim jsonData As String = fileReader.ReadToEnd
fileReader.Close()
Dim myJs = JsonConvert.DeserializeObject(Of Body)(jsonData)
When I expand myJS, it shows the data properties from my class but with no values.
JSON is this:
{
"Body" : {
"Data" : {
"DAY_PMAX" : {
"Unit" : "W",
"Value" : 2013
},
"DAY_UACMAX" : {
"Unit" : "V",
"Value" : 244.80000000000001
},
"DAY_UDCMAX" : {
"Unit" : "V",
"Value" : 375.19999999999999
},
"TOTAL_PMAX" : {
"Unit" : "W",
"Value" : 5568
},
"TOTAL_UACMAX" : {
"Unit" : "V",
"Value" : 285.5
},
"TOTAL_UDCMAX" : {
"Unit" : "V",
"Value" : 389.19999999999999
},
"YEAR_PMAX" : {
"Unit" : "W",
"Value" : 5562
},
"YEAR_UACMAX" : {
"Unit" : "V",
"Value" : 277.30000000000001
},
"YEAR_UDCMAX" : {
"Unit" : "V",
"Value" : 375.19999999999999
}
}
},
"Head" : {
"RequestArguments" : {
"DataCollection" : "MinMaxInverterData",
"DeviceClass" : "Inverter",
"DeviceId" : "1",
"Scope" : "Device"
},
"Status" : {
"Code" : 0,
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2021-07-22T11:34:44+10:00"
}
}
And classes are here:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Serialization
Public Class Body
<JsonProperty(PropertyName:="Body")>
Public Property Data As Data
End Class
Public Class Data
<JsonProperty(PropertyName:="DAY_PMAX")>
Public Property DAY_PMAX As DAYPMAX
<JsonProperty(PropertyName:="DAY_UACMAX")>
Public Property DAY_UACMAX As DAYUACMAX
<JsonProperty(PropertyName:="DAY_UDCMAX")>
Public Property DAY_UDCMAX As DAYUDCMAX
<JsonProperty(PropertyName:="TOTAL_PMAX")>
Public Property TOTAL_PMAX As TOTALPMAX
<JsonProperty(PropertyName:="TOTAL_UACMAX")>
Public Property TOTAL_UACMAX As TOTALUACMAX
<JsonProperty(PropertyName:="TOTAL_UDCMAX")>
Public Property TOTAL_UDCMAX As TOTALUDCMAX
<JsonProperty(PropertyName:="YEAR_PMAX")>
Public Property YEAR_PMAX As YEARPMAX
<JsonProperty(PropertyName:="YEAR_UACMAX")>
Public Property YEAR_UACMAX As YEARUACMAX
<JsonProperty(PropertyName:="YEAR_UDCMAX")>
Public Property YEAR_UDCMAX As YEARUDCMAX
End Class
Public Class DAYPMAX
Public Property Unit As String
Public Property Value As Integer
End Class
Public Class DAYUACMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class DAYUDCMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class TOTALPMAX
Public Property Unit As String
Public Property Value As Integer
End Class
Public Class TOTALUACMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class TOTALUDCMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class YEARPMAX
Public Property Unit As String
Public Property Value As Integer
End Class
Public Class YEARUACMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class YEARUDCMAX
Public Property Unit As String
Public Property Value As Double
End Class
Public Class RequestArguments
Public Property DataCollection As String
Public Property DeviceClass As String
Public Property DeviceId As String
Public Property Scope As String
End Class
Public Class Status
Public Property Code As Integer
Public Property Reason As String
Public Property UserMessage As String
End Class
Public Class Head
Public Property RequestArguments As RequestArguments
Public Property Status As Status
Public Property Timestamp As DateTime
End Class
Public Class Example
Public Property Body As Body
Public Property Head As Head
End Class

Your class model is missing the Root object. You can see it if you simplify the JSON structure: Body and Head are contained in an Object (hence, both are properties of the same Root object).
{
"Body" : {
},
"Head" : {
}
}
Add a Root object that contains these properties:
Public Class FroniusAPIRoot
Public Property Body As Body
Public Property Head As Head
End Class
I suggest to simplify the model: all those properties of the Data class are just one object Type and the JSON object property name is the Key to get the related object.
You can simply use a Dictionary(Of String, Class) to handle all the Properties of Data.
It's also more flexible, in case those properties can change or the API can return more/different objects, depending on the type of the query.
Partial Public Class Body
Public Property Data As Dictionary(Of String, UnitValues)
End Class
Public Class UnitValues
Public Property Unit As String
Public Property Value As Double
End Class
Use the FroniusAPIRoot class deserialize your JSON:
Dim json = File.ReadAllText("C:\Temp\JsonCrap.js")
Dim froniusData = JsonConvert.DeserializeObject(Of FroniusAPIRoot)(json)
Modified class model:
Note: I'm not sure whether RequestArguments.DeviceId should be interpreted as a string or an integer value. It's defined as string in the JSON. Modify as required (Integer, Long).
If you don't like the Dictionary, add back the Data class and all its properties, but use the UnitValues class to define the Type (since all can use the same Type).
Public Class FroniusAPIRoot
Public Property Body As Body
Public Property Head As Head
End Class
Public Class Body
Public Property Data As Dictionary(Of String, UnitValues)
End Class
Public Class UnitValues
Public Property Unit As String
Public Property Value As Double
End Class
Public Class Head
Public Property RequestArguments As RequestArguments
Public Property Status As Status
Public Property Timestamp As DateTimeOffset
End Class
Public Class RequestArguments
Public Property DataCollection As String
Public Property DeviceClass As String
Public Property DeviceId As String
Public Property Scope As String
End Class
Public Class Status
Public Property Code As Long
Public Property Reason As String
Public Property UserMessage As String
End Class

Related

Dynamic JSON Deserialization with VB.NET [duplicate]

This question already has answers here:
Deserializing JSON when sometimes array and sometimes object
(7 answers)
Closed 2 years ago.
I get an API response in JSON in following format
{
"stuffs": {
"prop1": "abcd",
"prop2": "efgh",
"prop3": [
{
"content": "123456",
"name": "abc def",
"id": "123"
},
{
"content": "789012",
"name": "def ghi",
"id": "456"
}
]
}
}
I have created my Class to deserialize this object as below
Public Class Prop3
Public Property content As String
Public Property name As String
Public Property id As String
End Class
Public Class Stuffs
Public Property prop1 As String
Public Property prop2 As String
Public Property prop3 As Prop3()
End Class
Public Class Example
Public Property stuffs As Stuffs
End Class
Now the issue is, sometime, the response is not an array for prop3 and looks like this
{
"stuffs": {
"prop1": "abcd",
"prop2": "efgh",
"prop3": {
"content": "123456",
"name": "abc def",
"id": "123"
}
}
}
This time I get error while deserializing as the prop3 is not array anymore bu the property declared inside my class stuffs is expecting an array of property prop3.
Is there any dynamic way to resolve this? Like if the JSON response is an array it will be treated as array
Public Property prop3 As Prop3()
and in case it is not an array then it will treated as single property
Public Property prop3 As Prop3
Please suggest how to overcome this as changing the response from the API is not feasible because it is being developed by client and I need to use it my application, so I need to find some dynamic way to resolve this.
After suggestion made by Craig, I have tried in the below way, but still it is not happening, please suggest if I am making any mistake.
Public Class SingleValueArrayConverter(Of T)
Inherits JsonConverter
Public Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal value As Object, ByVal serializer As JsonSerializer)
serializer.Serialize(writer, value)
End Sub
Public Overrides Function ReadJson(ByVal reader As JsonReader, ByVal objectType As Type, ByVal existingValue As Object, ByVal serializer As JsonSerializer) As Object
Dim retVal As Object = New Object()
If reader.TokenType = JsonToken.StartObject Then
Dim instance As T = CType(serializer.Deserialize(reader, GetType(T)), T)
retVal = New List(Of T)() From {
instance
}
ElseIf reader.TokenType = JsonToken.StartArray Then
retVal = serializer.Deserialize(reader, objectType)
End If
Return retVal
End Function
Public Overrides Function CanConvert(ByVal objectType As Type) As Boolean
Return True
End Function
End Class
Public Class myClass1
Public Class Prop3
Public Property content As String
Public Property name As String
Public Property id As String
End Class
Public Class Stuffs
Public Property prop1 As String
Public Property prop2 As String
<JsonProperty("prop3")>
<JsonConverter(GetType(SingleValueArrayConverter(Of Prop3)))>
Public Property prop3 As Prop3()
End Class
Public Class Example
Public Property stuffs As Stuffs
End Class
End Class
It gives error:
Unable to cast object of type 'SingleValueArrayConverter`1[myClass1.myClass+Prop3]' to type 'Newtonsoft.Json.JsonConverter'.'
Any highlight on what I am missing please.
It worked after changing
Public Property prop3 As Prop3()
to
Public Property prop3 As List(Of Prop3)

Generating Class VB.NET

I was using JSON Utils to generate a Class and I came to a problem. The JSON string I'm using:
{
"type": "champion",
"version": "7.16.1",
"data": {
"1": {
"title": "the Dark Child",
"id": 1,
"key": "Annie",
"name": "Annie"
}
}
}
The Class it generates:
Public Class 1
Public Property title As String
Public Property id As Integer
Public Property key As String
Public Property name As String
End Class
Public Class Data
Public Property 1 As 1
End Class
Public Class Example
Public Property type As String
Public Property version As String
Public Property data As Data
End Class
The thing is that I cannot name a Class 1, I am still trying to find a solution but with no luck yet. Is there a work around this?
I think it should be change to Dictionary
Public Class Example
Public Property type As String
Public Property version As String
Public Property data As Dictionary(Of String, NumberType)
End Class
Public Class NumberType
Public Property title As String
Public Property id As Integer
Public Property key As String
Public Property name As String
End Class

Cannot Json deserialize Youtube data with VB.net

I need to obtain the "title" from the response i get from Youtube.
I get the following error at line 8, position 12, that is, at line:
"items": [
just after the "["
The error i get is:
Exception: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll ("Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'categoryid.Item' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path 'items', line 8, position 12."). Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll ("Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'categoryid.Item' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path 'items', line 8, position 12.") 2.61s [12096] <No Name>
I have this code:
Dim m As IEnumerable(Of Rootobject) = JsonConvert.DeserializeObject(Of IEnumerable(Of Rootobject))(res)
with this JSON data:
{
"kind":"youtube#videoListResponse",
"etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/jznkhy3_Aws9VtommTkcdOYnAAk\"",
"pageInfo":{
"totalResults":1,
"resultsPerPage":1
},
"items":[
{
"kind":"youtube#video",
"etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/M_wQmC4lQBaHJGxo79N7WlmqNr8\"",
"id":"SSbBvKaM6sk",
"snippet":{
"publishedAt":"2009-04-15T20:31:11.000Z",
"channelId":"UC2kTZB_yeYgdAg4wP2tEryA",
"title":"Blur - Song 2",
"description":"Blur 21 -- Celebrating 21 years of Blur. To find out more, click here:http://smarturl.it/blur21y\n\n#blur21\n \nFollow Blur on Twitter:www.twitter.com/blurofficial \nFind Blur on Facebook:www.facebook.com/blur\n\nMusic video by Blur performing Song 2.",
"thumbnails":{
"default":{
"url":"https://i.ytimg.com/vi/SSbBvKaM6sk/default.jpg",
"width":120,
"height":90
},
"medium":{
"url":"https://i.ytimg.com/vi/SSbBvKaM6sk/mqdefault.jpg",
"width":320,
"height":180
},
"high":{
"url":"https://i.ytimg.com/vi/SSbBvKaM6sk/hqdefault.jpg",
"width":480,
"height":360
},
"standard":{
"url":"https://i.ytimg.com/vi/SSbBvKaM6sk/sddefault.jpg",
"width":640,
"height":480
},
"maxres":{
"url":"https://i.ytimg.com/vi/SSbBvKaM6sk/maxresdefault.jpg",
"width":1280,
"height":720
}
},
"channelTitle":"emimusic",
"tags":[
"Blur",
"Song"
],
"categoryId":"10",
"liveBroadcastContent":"none",
"localized":{
"title":"Blur - Song 2",
"description":"Blur 21 -- Celebrating 21 years of Blur. To find out more, click here:http://smarturl.it/blur21y\n\n#blur21\n \nFollow Blur on Twitter:www.twitter.com/blurofficial \nFind Blur on Facebook:www.facebook.com/blur\n\nMusic video by Blur performing Song 2."
}
},
"contentDetails":{
"duration":"PT2M3S",
"dimension":"2d",
"definition":"sd",
"caption":"false",
"licensedContent":true,
"regionRestriction":{
"allowed":[
"BY",
"US"
]
},
"projection":"rectangular"
}
}
]
}
and these classes. the classes are pasted as special with the visual studio 2015 option.
Public Class Rootobject
Public Property kind As String
Public Property etag As String
Public Property pageInfo As Pageinfo
Public Property items() As Item
End Class
Public Class Pageinfo
Public Property totalResults As Integer
Public Property resultsPerPage As Integer
End Class
Public Class Item
Public Property kind As String
Public Property etag As String
Public Property id As String
Public Property snippet As Snippet
Public Property contentDetails As Contentdetails
End Class
Public Class Snippet
Public Property publishedAt As Date
Public Property channelId As String
Public Property title As String
Public Property description As String
Public Property thumbnails As Thumbnails
Public Property channelTitle As String
Public Property tags() As String
Public Property categoryId As String
Public Property liveBroadcastContent As String
Public Property localized As Localized
End Class
Public Class Thumbnails
Public Property _default As _Default
Public Property medium As Medium
Public Property high As High
Public Property standard As Standard
Public Property maxres As Maxres
End Class
Public Class _Default
Public Property url As String
Public Property width As Integer
Public Property height As Integer
End Class
Public Class Medium
Public Property url As String
Public Property width As Integer
Public Property height As Integer
End Class
Public Class High
Public Property url As String
Public Property width As Integer
Public Property height As Integer
End Class
Public Class Standard
Public Property url As String
Public Property width As Integer
Public Property height As Integer
End Class
Public Class Maxres
Public Property url As String
Public Property width As Integer
Public Property height As Integer
End Class
Public Class Localized
Public Property title As String
Public Property description As String
End Class
Public Class Contentdetails
Public Property duration As String
Public Property dimension As String
Public Property definition As String
Public Property caption As String
Public Property licensedContent As Boolean
Public Property regionRestriction As Regionrestriction
Public Property projection As String
End Class
Public Class Regionrestriction
Public Property allowed() As String
End Class
What i need to do?
Thanks in advance.
You are getting that exception because you have declared several auto-implemented array properties incorrectly. As shown in Auto-Implemented Properties (Visual Basic) such properties should be declared as follows, with the () array indicator as part of the return type:
Public Property items As Item()
Instead you declare them as follows:
Public Property items() As Item
This declares a property returning a single Item rather than an array of them. The () attached to the property name is optional; for parameterless properties it is redundant but for properties taking parameters the argument list appears there. See the documentation page Property Statement for details. Then Json.NET throws the exception you see when attempting to deserialize a JSON array into one of the non-array properties in your model.
To fix this, three of your classes should be modified as follows:
Public Class Rootobject
Public Property kind As String
Public Property etag As String
Public Property pageInfo As Pageinfo
Public Property items As Item() ' Fixed
End Class
Public Class Snippet
Public Property publishedAt As Date
Public Property channelId As String
Public Property title As String
Public Property description As String
Public Property thumbnails As Thumbnails
Public Property channelTitle As String
Public Property tags As String() ' Fixed
Public Property categoryId As String
Public Property liveBroadcastContent As String
Public Property localized As Localized
End Class
Public Class Regionrestriction
Public Property allowed As String() ' Fixed
End Class
Then, since the items are an array, to access the titles and put then in a list, you can use extension methods from System.Linq.Enumerable:
' Convert the json string to RootObject.
Dim root = JsonConvert.DeserializeObject(Of Rootobject)(json)
' Extract the list of titles.
Dim titles = root.items _
.Select(Function(i) i.snippet.title) _
.ToList()
' Get the first title in the list.
Dim firstTitle = titles.FirstOrDefault()
Console.WriteLine("First title = ""{0}""", firstTitle)
Which prints out First title = "Blur - Song 2".
Sample VB.Net fiddle.

Parsing Json in vb.net with newtonsot.json

I have the following json string
{
"extractorData" : {
"url" : "http://absa.co.za/Absacoza/Indices/Absa-Exchange-Rates",
"resourceId" : "4dd52d44301ebd50db87975bf5df9711",
"data" : [ {
"group" : [ {
"absa" : [ {
"text" : "USD"
} ]
}, {
"absa" : [ {
"text" : "US Dollar"
} ]
}, {
"absa" : [ {
"text" : "*"
} ]
}, {
"absa" : [ {
"text" : "14.429"
} ],
"Buying" : [ {
"text" : "14.429"
} ]
}, {
"absa" : [ {
"text" : "14.409"
} ]
}, {
"absa" : [ {
"text" : "14.404"
} ]
}, {
"absa" : [ {
"text" : "14.8323"
} ],
"Selling" : [ {
"text" : "14.8323"
} ]
}, {
"absa" : [ {
"text" : "14.8373"
} ]
} ]
} ]
},
"pageData" : {
"statusCode" : 200,
"timestamp" : 1459675946038
}
}
I also created the following classes
Public Class Rootobject
Public Property extractorData As Extractordata
Public Property pageData As Pagedata
End Class
Public Class Extractordata
Public Property url As String
Public Property resourceId As String
Public Property data() As Datum
End Class
Public Class Datum
Public Property group() As Group
End Class
Public Class Group
Public Property absa() As Absa
Public Property Buying() As Buying
Public Property Selling() As Selling
End Class
Public Class Absa
Public Property text As String
End Class
Public Class Buying
Public Property text As String
End Class
Public Class Selling
Public Property text As String
End Class
Public Class Pagedata
Public Property statusCode As Integer
Public Property timestamp As Long
End Class
How can I extract the values for Buying and Selling using newtonsoft.json? I have been looking at and trying examples for the past 4 hours and I am still no closer to an answer. I am very new to json
please help
Apparently your code does not desertizare correctly because of the way you define the arrays. Putting it in the form of Public Property data As List(Of Datum) (and so on) instead of Public Property data() As Datum solves the issue.
The full and tested code can be found here. This is how you deserialize the json text:
Sub Main()
Dim jsonAsText = File.ReadAllText("C:\Path\To\json.txt")
Dim deserializedRootObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of RootObject)(jsonAsText)
End Sub
This deserialization uses RootObject and its sub-objects, which are shown here:
Public Class Absa
Public Property text As String
End Class
Public Class Buying
Public Property text As String
End Class
Public Class Selling
Public Property text As String
End Class
Public Class Group
Public Property absa As List(Of Absa)
Public Property Buying As List(Of Buying)
Public Property Selling As List(Of Selling)
End Class
Public Class Datum
Public Property group As List(Of Group)
End Class
Public Class ExtractorData
Public Property url As String
Public Property resourceId As String
Public Property data As List(Of Datum)
End Class
Public Class PageData
Public Property statusCode As Integer
Public Property timestamp As Long
End Class
Public Class RootObject
Public Property extractorData As ExtractorData
Public Property pageData As PageData
End Class
You can try example Bellow taken from newtonsoft.com
string json = #"{
'Email': 'james#example.com',
'Active': true,
'CreatedDate': '2013-01-20T00:00:00Z',
'Roles': [
'User',
'Admin'
]
}";
Account account = JsonConvert.DeserializeObject<Account>(json);
Console.WriteLine(account.Email);
http://www.newtonsoft.com/json/help/html/deserializeobject.htm

DataContract Json Serializer and missing bracket in collection of items

When I de-serialize/serialize and data contract to a json format my collection of items is missing the bracket and is causing it fail when posting to web api.
Here is the json in the correct format with [] brackets
{
"basket": {
"basket_platform_type": "in_store",
"basket_currency": {
"currency_id": 2,
"currency_code": "ZAR"
},
"basket_items": [
{
"spaaza_product_id": 18605,
"retailer_product_code": "WBGT0234",
"retailer_item_code": "line_0",
"item_quantity": 3,
"item_price": 250
}
],
"retailer_basket_code": "70401",
"basket_total_price": 750
},
"entity": {
"entity_type": "chain",
"entity_id": 1740,
"branch_business_owner_code": "501",
"branch_business_id": 1341
},
"user": {
"member_programme": "spaaza",
"member_number": "33017307"
}
}
This is what I get, I am missing the [] at basketitems
{
"basket": {
"basket_platform_type": "in_store",
"basket_currency": {
"currency_id": 2,
"currency_code": "ZAR"
},
"basket_items":
{
"spaaza_product_id": 18605,
"retailer_product_code": "WBGT0234",
"retailer_item_code": "line_0",
"item_quantity": 3,
"item_price": 250
},
"retailer_basket_code": "70401",
"basket_total_price": 750
},
"entity": {
"entity_type": "chain",
"entity_id": 1740,
"branch_business_owner_code": "501",
"branch_business_id": 1341
},
"user": {
"member_programme": "spaaza",
"member_number": "33017307"
}
}
Here is classes and the functions I am using for serialization.
Namespace Global.MyPrice
Public Class GetBasketPrice
Public Class Entity
Public Property entity_type As String
Public Property entity_id As Integer
Public Property branch_business_owner_code As String
Public Property branch_business_id As Integer
End Class
Public Class User
Public Property member_programme As String
Public Property member_number As String
End Class
Public Class Basket_Currency
Public Property currency_id As Integer
Public Property currency_code As String
End Class
Public Class Rootobject
Public Property basket As Basket
Public Property entity As Entity
Public Property user As User
End Class
Public Class Basket_Items
Public Property spaaza_product_id As Integer
Public Property retailer_product_code As String
Public Property retailer_item_code As String
Public Property item_quantity As Integer
Public Property item_price As Single
End Class
Public Class Basket
Public Property basket_platform_type As String
Public Property basket_currency As Basket_Currency
Public Property basket_items() As Basket_Items
Public Property retailer_basket_code As String
Public Property basket_total_price As Single
End Class
End Class
End Namespace
This is the serialization function
Dim jsonstring As String
Dim stream1 As New MemoryStream()
Dim ser As New DataContractJsonSerializer(GetType(MyPrice.GetBasketPrice.Rootobject))
ser.WriteObject(stream1, MyPriceBasket)
stream1.Position = 0
Dim sr As New StreamReader(stream1)
Console.Write("JSON form of Person object: ")
jsonstring = sr.ReadToEnd()
Console.WriteLine(jsonstring)
The value for "basket_items" is a JSON array, which is a bracketed list of values: [value1, value2, ..., valueN]. According to the documentation, DataContractJsonSerializer maps "Collections, dictionaries, and arrays" to a JSON array. Thus your basket_items property needs to be a collection of some sort, for instance a List(Of Basket_Items):
Public Class Basket
Public Property basket_platform_type As String
Public Property basket_currency As Basket_Currency
Public Property basket_items As List(Of Basket_Items)
Public Property retailer_basket_code As String
Public Property basket_total_price As Single
End Class
Or, if you want to use an array rather than a list, your () is in the wrong location. You define an array-valued property in VB.NET like this:
Public Property basket_items As Basket_Items()
More here.