I get a Json file from our data provider without any information about the datatype of the data inside. The Json comprises only the data and one entry looks like this (this is survey data and one entry is the data of one person):
{"data":["4482359","12526","2014 Company Y","2","3","1"]}
I deserialized the file and have it within an object now but all entries are strings. I want to import it into a database but each entry should have the datatype that it best fits to it. E.g. 1 is int16, 2014 Company Y is string. Acutally I have only Int16 and String, nothing more. For importing it into the database I acutally need the Sql Server datatype equivalent. Unfortunately I cannot hardcode the datatype into the Table Creation Command since the order of the data is not the same for each query. E.g. First I receive Survey 1 data with the structure shown above. But maybe a few days later I need different data like
{"data":["4482359","2","3","1","12526","2015 Company X"]}
Deserialized the Json Data I have an object (RootObject) with a List(of String) called data. Where the first string is "4482359" the second is "2" the third is "3" and so on.
Public Class RootObject
Public Property data As List(Of String)
End Class
Public Class RootObjectDatatype
Private _rootObject As RootObject
Public Sub New(ByRef rootObject As RootObject)
For Each str As String In rootObject.data
If str > 0 And str < 50000 Then
jsonDatatype.Add("Int")
Else
jsonDatatype.Add("Varchar(" & str.Count & ")")
End If
Next
End Sub
Public Property jsonDatatype As List(Of String)
End Class
But this does not work yet.
>` with the values, pass each `List` to the specialized class that will return a new class object with the string members converted to the correct type, corresponding to the Database field types.
– Jimi Jan 23 '19 at 15:00