Extract data from a JSON received from an HTTP response - json

So I have an HTTP response that gives me this data:
{
"result":"success",
"records":{
"509442013":{
"nif":509442013,
"seo_url":"nexperience-lda",
"title":"Nexperience Lda",
"address":"Rua da Lionesa Nº 446, Edifício G20",
"pc4":"4465",
"pc3":"671",
"city":"Leça do Balio",
"activity":"Desenvolvimento de software. Consultoria em informática. Comércio de equipamentos e sistemas informáticos. Exploração de portais web.",
"status":"active",
"cae":"62010",
"contacts":{
"email":"info#nex.pt",
"phone":"220198228",
"website":"www.nex.pt",
"fax":"224 905 459"
},
"structure":{
"nature":"LDA",
"capital":"5000.00",
"capital_currency":"EUR"
},
"geo":{
"region":"Porto",
"county":"Matosinhos",
"parish":"Leça do Balio"
},
"place":{
"address":"Rua da Lionesa Nº 446, Edifício G20",
"pc4":"4465",
"pc3":"671",
"city":"Leça do Balio"
},
"racius":"http://www.racius.com/nexperience-lda/",
"alias":"Nex - Nexperience, Lda",
"portugalio":"http://www.portugalio.com/nex/"
}
},
"nif_validation":true,
"is_nif":true,
"credits":{
"used":"free",
"left":[
]
}
}
And I need to extract some data from it, like the fields:
NIF
title
and the email and phone that are inside the contacts array.
I need the data to populate some TextBoxes in my Form.
To get the http response I have this button but I don't know how to extract the data I need.
Can someone help me?
My code:
Private Sub Btn_NIFImport_Click(sender As Object, e As EventArgs) Handles Btn_NIFImport.Click
Dim key As String = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
Try
'Create the request
Dim request As HttpWebRequest = HttpWebRequest.Create("http://www.nif.pt/?json=1&q=" & Txt_NIFImport.Text & "&key=" & key)
request.Proxy = Nothing
request.UserAgent = "Test"
'Create the response reader
Dim response As HttpWebResponse = request.GetResponse
Dim responseStream As System.IO.Stream = response.GetResponseStream
'Create a new stream reader
Dim streamReader As New System.IO.StreamReader(responseStream)
Dim data As String = streamReader.ReadToEnd
streamReader.Close()
'Display the data on the screen
Txt_Teste.Text = data
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Thanks in advance.

after you get the response from the http request you need to deserialize the json to an object in vb.net
To Classes to create the object by your json:
Public Class [Structure]
Public Property nature As String
Public Property capital As String
Public Property capital_currency As String
End Class
Public Class Geo
Public Property region As String
Public Property county As String
Public Property parish As String
End Class
Public Class Place
Public Property address As String
Public Property pc4 As String
Public Property pc3 As String
Public Property city As String
End Class
Public Class Record
Public Property nif As Integer
Public Property seo_url As String
Public Property title As String
Public Property address As String
Public Property pc4 As String
Public Property pc3 As String
Public Property city As String
Public Property activity As String
Public Property status As String
Public Property cae As String
Public Property contacts As Contacts
Public Property [structure] As [Structure]
Public Property geo As Geo
Public Property place As Place
Public Property racius As String
Public Property [alias] As String
Public Property portugalio As String
End Class
Public Class Credits
Public Property used As String
Public Property left As List(Of Object)
End Class
Public Class Root
Public Property result As String
Public Property records As Dictionary(Of String, Record)
Public Property nif_validation As Boolean
Public Property is_nif As Boolean
Public Property credits As Credits
End Class
and to deserialize added after you get the response the following line:
Root l = JsonConvert.DeserializeObject<Root>(response);
EDIT:
I made some changes in the code so now you use with Dictionary that has KEY in your json '509442013' and value As Record (Notice that I change the class name as was before '_509442013')
And in the root changes
Public Property records As Dictionary(Of String, Record)
now this will work in each time even if you will get in each http request ID as class that not the same.
notice that the only way you can get the value is by the KEY you already pass in the http request.
Added GIF:
(In my case I change the ID and city, in the result show the city from the json)
Convert Button:
Dim jsonString As String = tbInput.Text
Dim l As Root = JsonConvert.DeserializeObject(Of Root)(jsonString)
tbResult.Text = l.records(tbKEY.Text.ToString).city.ToString()
tbKEY get the value from the screen like in my gif example.

Related

VB.Net_Having Problem with reading a token from JSON

I'm making a program that reads weather data from open weather map API
Here's the response(json):
coord
lon -0.1257
lat 51.5085
weather
0
id 802
main "Clouds"
description "scattered clouds"
icon "03d"
base "stations"
main
temp 22.43
feels_like 22.4
temp_min 19.82
temp_max 24.21
pressure 1021
humidity 64
visibility 10000
wind
speed 4.12
deg 270
clouds
all 40
dt 1625834363
sys
type 2
id 2006068
country "GB"
sunrise 1625802859
sunset 1625861805
timezone 3600
id 2643743
name "London"
cod 200
and here is the code I use to select tokens from json:
Imports System.Net
Imports System.IO
Imports Newtonsoft.Json.Linq
Public deg As String = Chr(176)
Public iconid As String = ""
Public locationstr As String
Public ApiKey As String = "MYAPIKEY"
#Region "Conditions"
Public windspeedMPS As String = ""
Public humidity As String = ""
Public description As String
Public cloudiness As String = ""
Public temp As String = ""
Public City As String = ""
#End Region
Public Sub getweather(ByVal key As String)
Dim req As HttpWebRequest = DirectCast(WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" & locationstr & "&appid=" & ApiKey & "&lang=en&units=metric"), HttpWebRequest)
Dim res As HttpWebResponse = DirectCast(req.GetResponse, HttpWebResponse)
Dim reader As New StreamReader(res.GetResponseStream)
Dim serverresponse As String = reader.ReadToEnd
Dim json As String = serverresponse
Dim obj As JObject = JObject.Parse(json)
Try
windspeddMPS = obj.SelectToken("wind").SelectToken("speed")
humidity = obj.SelectToken("main").SelectToken("humidity")
description = obj.SelectToken("weather").SelectToken("description")
cloudiness = obj.SelectToken("clouds").SelectToken("all")
temp = obj.SelectToken("main").SelectToken("temp")
City = obj.SelectToken("name")
iconid = obj.SelectToken("weather").SelectToken("icon")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I can select all the tokens except "description"(weather condition within a group) and "icon"(weather condition icon id) tokens.
For reference, here is the documentation for the web API you're using: https://openweathermap.org/current
Visual Studio has a cool feature called Paste JSON as Classes that can be found under Edit > Paste Special > Paste JSON as Classes. If you were to do this, then you would get something that looks like the following:
Public Class Rootobject
Public Property coord As Coord
Public Property weather() As Weather
Public Property base As String
Public Property main As Main
Public Property visibility As Integer
Public Property wind As Wind
Public Property clouds As Clouds
Public Property dt As Integer
Public Property sys As Sys
Public Property timezone As Integer
Public Property id As Integer
Public Property name As String
Public Property cod As Integer
End Class
Public Class Coord
Public Property lon As Single
Public Property lat As Single
End Class
Public Class Main
Public Property temp As Single
Public Property feels_like As Single
Public Property temp_min As Single
Public Property temp_max As Single
Public Property pressure As Integer
Public Property humidity As Integer
End Class
Public Class Wind
Public Property speed As Single
Public Property deg As Integer
End Class
Public Class Clouds
Public Property all As Integer
End Class
Public Class Sys
Public Property type As Integer
Public Property id As Integer
Public Property message As Single
Public Property country As String
Public Property sunrise As Integer
Public Property sunset As Integer
End Class
Public Class Weather
Public Property id As Integer
Public Property main As String
Public Property description As String
Public Property icon As String
End Class
From here, you can deserialize the JSON response to the Rootobject class which in turn you have access to strongly typed objects to get your values:
' ... HTTP request to get JSON
Dim jsonObject = JsonConvert.DeserializeObject(Of Rootobject)(json)
Console.WriteLine(jsonObject.clouds.all)

How To Deserialize JSON in vb,net with Multiple objects

Below is a json file that needs to be deserialized and to be stored in different variables.
With this current json, which is returned by an API, I am unable to deserialize because it gives me and error -
Please help me on deserializing this particular json
I have added the code i used, but it returns wrong values and null reference.
{
"result": {
"candidates": [
{
"similarity": 0.1330482513,
"person_id": "75741ea3-4d9b-4e25-8460-16444ee39946",
"descriptor_id": "2f228007-350e-4d58-9897-4b62e9978081",
"user_data": "Без названия (9)",
"external_id": null
}
],
"face": {
"id": "a1b224a3-60c6-4733-9bbc-136d53ea011c",
"score": 0.9320185781
}
},
"timestamp": 1569957900.1488559,
"source": "search",
"event_type": "match",
"authorization": {
"token_id": "71f9b3e0-51b1-480f-93b9-0e76e260bcbc",
"token_data": "first token"
},
"template": {
"descriptor_id": "a1b224a3-60c6-4733-9bbc-136d53ea011c"
},
"candidate": {
"list_id": "6e64e600-cd77-4894-940e-6f7022d8aba8",
"list_data": "FaceStream_search_list(DON'T DELETE)",
"list_type": 1
}
}
I have tried :
Public Class Rootobject
Public Property result As Result
Public Property timestamp As Single
Public Property source As String
Public Property event_type As String
Public Property authorization As Authorization
Public Property template As Template
Public Property candidate As Candidate1
End Class
Public Class Result
Public Property candidates() As Candidate
Public Property face As Face
End Class
Public Class Face
Public Property id As String
Public Property score As Single
End Class
Public Class Candidate
Public Property similarity As Double
Public Property person_id As String
Public Property descriptor_id As String
Public Property user_data As String
Public Property external_id As Object
End Class
Public Class Authorization
Public Property token_id As String
Public Property token_data As String
End Class
Public Class template
Public Property descriptor_id As String
End Class
Public Class Candidate1
Public Property list_id As String
Public Property list_data As String
Public Property list_type As Integer
End Class
''And used
Dim Candidatess As New Candidate
Candidatess = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Candidate)((JObject.Parse(e.Message)).ToString)
msg(Candidatess.similarity.ToString)
msg(Candidatess.descriptor_id.ToString)
msg(Candidatess.person_id.ToString)
''REturns me Null
Public Class Candidate
Public Property similarity As Double
Public Property person_id As String
Public Property descriptor_id As String
Public Property user_data As String
Public Property external_id As Object
End Class
Public Class Face
Public Property id As String
Public Property score As Double
End Class
Public Class Result
Public Property candidates As Candidate()
Public Property face As Face
End Class
Public Class Authorization
Public Property token_id As String
Public Property token_data As String
End Class
Public Class Template
Public Property descriptor_id As String
End Class
Public Class Candidate
Public Property list_id As String
Public Property list_data As String
Public Property list_type As Integer
End Class
Public Class Candidates
Public Property result As Result
Public Property timestamp As Double
Public Property source As String
Public Property event_type As String
Public Property authorization As Authorization
Public Property template As Template
Public Property candidate As Candidate
End Class
Public Function GetData(ApiEndpoint As Uri, ApiToken As String)
Dim origResponse As HttpWebResponse = Nothing
Dim objResponse As HttpWebResponse = Nothing
Dim origReader As StreamReader = Nothing
Dim objReader As StreamReader = Nothing
Dim origRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(ApiEndpoint), HttpWebRequest)
origRequest.Headers.Add("Authorization", "Basic " & ApiToken)
origRequest.AllowAutoRedirect = False
origRequest.Method = "GET"
'Call the API and get the JSON Response data
origResponse = DirectCast(origRequest.GetResponse(), HttpWebResponse)
Dim Stream As Stream = origResponse.GetResponseStream()
Dim sr As New StreamReader(Stream, Encoding.GetEncoding("utf-8"))
Dim myJsonResponse As String = sr.ReadToEnd()
'Deserialize the Json
Dim objFormResults As Result = JsonConvert.DeserializeObject(Of Result)(myJsonResponse)
'loop through the results
End Function

Deserialize this JSON string

I always get the error:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Test.Form15+results[]]' 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 'result', line 1, position 10.
My code is as follows and i'm not sure if it's the double-quotes causing the issues, or the bracket at the start of the json string. Any tips would be appreciated.
Public Class Form15
Public Class UTicketContact
<JsonProperty("display_value")>
Public Property DisplayValue As String
<JsonProperty("link")>
Public Property Link As String
End Class
Public Class URequestedFor
<JsonProperty("display_value")>
Public Property DisplayValue As String
<JsonProperty("link")>
Public Property Link As String
End Class
Public Class AssignedTo
<JsonProperty("display_value")>
Public Property DisplayValue As String
<JsonProperty("link")>
Public Property Link As String
End Class
Public Class OpenedBy
<JsonProperty("display_value")>
Public Property DisplayValue As String
<JsonProperty("link")>
Public Property Link As String
End Class
Public Class AssignmentGroup
<JsonProperty("display_value")>
Public Property DisplayValue As String
<JsonProperty("link")>
Public Property Link As String
End Class
Public Class Result
<JsonProperty("u_ticket_contact")>
Public Property UTicketContact As UTicketContact
<JsonProperty("u_requested_for")>
Public Property URequestedFor As URequestedFor
<JsonProperty("assigned_to")>
Public Property AssignedTo As AssignedTo
<JsonProperty("opened_by")>
Public Property OpenedBy As OpenedBy
<JsonProperty("assignment_group")>
Public Property AssignmentGroup As AssignmentGroup
End Class
Public Class results
<JsonProperty("result")>
Public Property Result As Result()
End Class
Function FindRequestedFor(ByVal instancename As String,
ByVal rtask As String) As String
Dim requestedfor As String = ""
'Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
Dim accessToken As String = GenerateToken("instancenameredacted",
"clientIdredacted",
"clientSecretredacted",
"accountredacted",
"accountpasswordredacted")
Dim url As String = "https://" & instancename & ".service-now.com/api/ubis2/request/rtask?query=number%3D" & rtask
Dim request As WebRequest = WebRequest.Create(url)
Dim dataStream As Stream
request.ContentType = "application/json; charset=utf-8"
request.Method = "GET"
request.Headers.Add("Authorization", "Bearer " & accessToken)
dataStream = request.GetResponse.GetResponseStream
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd
'Format of the JSON string is: ""{
""result"": [
{
""u_ticket_contact"": {
""display_value"": ""Name1"",
""link"": ""https://instance.service-now.com/api/now/table/sys_user/470104cf600ad400808370bee6ad2596""
},
""u_requested_for"": {
""display_value"": ""Name2"",
""link"": ""https://instance.service-now.com/api/now/table/sys_user/470104cf600ad400808370bee6ad2596""
},
""assigned_to"": {
""display_value"": ""Name3"",
""link"": ""https://instance.service-now.com/api/now/table/sys_user/98c7a3e5ac723040773cf2044a10de0c""
},
""opened_by"": {
""display_value"": ""Name4"",
""link"": ""https://instance.service-now.com/api/now/table/sys_user/470104cf600ad400808370bee6ad2596""
},
""assignment_group"": {
""display_value"": ""Group Name1"",
""link"": ""https://instance.service-now.com/api/now/table/sys_user_group/bad979fa19c44a40b5a0d99e2b982e75""
}
}
]
}""
Console.WriteLine(responseFromServer)
reader.Close()
dataStream.Close()
Dim test = JsonConvert.DeserializeObject(Of List(Of results()))(responseFromServer)
End Function
end class
I would use List(Of Result) type with initialization as below:
Public Class results
<JsonProperty("result")>
Public Property Result As New List(Of Result)
End Class

Deserialize this json in VB.NET

I have this json response:
{
"tracked_until": "1483704963",
"solo_competitive_rank": "4066",
"competitive_rank": "3821",
"mmr_estimate": {
"estimate": 3971,
"stdDev": 215.26495302301302,
"n": 20
},
"profile": {
"account_id": 131505839,
"personaname": "LeG",
"name": null,
"cheese": 1,
"steamid": "76561198091771567",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/c0/c09ca9b316ff7bf7dccba6f5a32aba97b8dba05c.jpg",
"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/c0/c09ca9b316ff7bf7dccba6f5a32aba97b8dba05c_medium.jpg",
"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/c0/c09ca9b316ff7bf7dccba6f5a32aba97b8dba05c_full.jpg",
"profileurl": "http://steamcommunity.com/id/LegLabs/",
"last_login": "2016-11-11T13:13:18.651Z",
"loccountrycode": "AL"
}
}
Using an Online Tool, I created these classes:
<Serializable>
Public Class mmr_estimate
Public Property estimate As String
Public Property stdDev As String
Public Property n As String
End Class
<Serializable>
Public Class profile
Public Property account_id As String
Public Property personaname As String
Public Property name As String
Public Property cheese As String
Public Property steamid As String
Public Property avatar As String
Public Property avatarmedium As String
Public Property avatarfull As String
Public Property profileurl As String
Public Property last_login As String
Public Property loccountrycode As String
End Class
<Serializable>
Public Class RootObject
Public Property tracked_until As String
Public Property solo_competitive_rank As String
Public Property competitive_rank As String
Public Property mmr_estimate As mmr_estimate
Public Property profile As profile
End Class
Then I use this code to deserialize it:
Dim steamData As String = ' the json contents above
Dim myjss As New JavaScriptSerializer()
Dim playerDictionary = myjss.Deserialize(Of List(Of RootObject))(steamData)
But the result I get is nothing, playerDictionary has 0 items, when it should have 1 item with the contents of the json parsed into KeyValuePairs.
If I use this piece of code
Dim data = myjss.DeserializeObject(steamData)
and then run a for each loop on the data elements, I can see the contents of data when debugging, but I don't know how to work with them like that, since they are just objects which I'm having trouble converting into KeyValuePairs, who in themselves may contain arrays of KeyValuePairs.
What I'm trying to get is the values of solo_competitive_rank, competitive_rank and steamid, but if I can't get the whole contents deserialized, I can't do that.
Are the declared classes wrong?
but with this solution you use not the class RootObject.
With first method, your JSON want in the list with key and value.
This is only for JSON Array. :(
rg

Deserialization using JSON.Net return null for all fields (VB)

I can't figure it out why ALL fields return null. My classes seem correct and fit the json perfectly. I used the JSON Util tool to convert my JSON result to VB (http://jsonutils.com/). I tried the project in C# but end up resulting the same problem. I'm using RestSharp to make my request and JSON.NET to deserialize my object.
Note that the RestSharp content is not empty and is equal to the JSON i added below.
Here is the Json :
{"customer":{"created_at":"2015-10-10T16:35:07-04:00","cust_identifier":null,"description":null,"domains":null,"id":8000039822,"name":"ACTION VEHICULES D'OCCASION","note":null,"sla_policy_id":8000012148,"updated_at":"2015-10-15T09:43:09-04:00","custom_field":{"cf_etat_client":"NO","cf_dealer_code":"U4504033884","cf_manufacturer":"Used","cf_email":null,"cf_province":"QU\u00c9BEC","cf_region":null,"cf_address":"1913 CH CHAMBLY","cf_city":"CARIGNAN","cf_postal_code":null,"cf_phone_":"450 403-3884","cf_fax":null,"cf_tollfree":null,"cf_legal_name":"ACTION VEHICULES D'OCCASION","cf_dealer_princ":null,"cf_g_manager":null,"cf_cfo_finance":null,"cf_sales_manager":null,"cf_trade_resp":null,"cf_used_veh_manager":null,"cf_business_manager_1":null,"cf_business_manager_2":null,"cf_email_g_manager":null,"cf_email_gs_manager":null,"cf_email_s_manager":null,"cf_email_trade":null,"cf_fleet_lease":null,"cf_accounting":null,"cf_installed":null,"cf_demo":null,"cf_update":null,"cf_sold":null,"cf_dealer_website":null,"cf_i_t_contact":null,"cf_server_name":null,"cf_network":null,"cf_is_domain":null,"cf_easybackup":null,"cf_password":null,"cf_pc_installed":null,"cf_reference_by":null,"cf_error_":null,"cf_license_":null,"cf_is_amvoq":true}}}
Here both of my class i used to deserialize :
Public Class Customer
Public Property created_at As DateTime
Public Property cust_identifier As Object
Public Property description As Object
Public Property domains As Object
Public Property id As Long
Public Property name As String
Public Property note As Object
Public Property sla_policy_id As Long
Public Property updated_at As DateTime
Public Property custom_field As CustomField
End Class
Public Class CustomField
Public Property cf_etat_client As String
Public Property cf_dealer_code As String
Public Property cf_manufacturer As String
Public Property cf_email As Object
Public Property cf_province As String
Public Property cf_region As Object
Public Property cf_address As String
Public Property cf_city As String
Public Property cf_postal_code As Object
Public Property cf_phone_ As String
Public Property cf_fax As Object
Public Property cf_tollfree As Object
Public Property cf_legal_name As String
Public Property cf_dealer_princ As Object
Public Property cf_g_manager As Object
Public Property cf_cfo_finance As Object
Public Property cf_sales_manager As Object
Public Property cf_trade_resp As Object
Public Property cf_used_veh_manager As Object
Public Property cf_business_manager_1 As Object
Public Property cf_business_manager_2 As Object
Public Property cf_email_g_manager As Object
Public Property cf_email_gs_manager As Object
Public Property cf_email_s_manager As Object
Public Property cf_email_trade As Object
Public Property cf_fleet_lease As Object
Public Property cf_accounting As Object
Public Property cf_installed As Object
Public Property cf_demo As Object
Public Property cf_update As Object
Public Property cf_sold As Object
Public Property cf_dealer_website As Object
Public Property cf_i_t_contact As Object
Public Property cf_server_name As Object
Public Property cf_network As Object
Public Property cf_is_domain As Object
Public Property cf_easybackup As Object
Public Property cf_password As Object
Public Property cf_pc_installed As Object
Public Property cf_reference_by As Object
Public Property cf_error_ As Object
Public Property cf_license_ As Object
Public Property cf_is_amvoq As Boolean
End Class
Here is the Deserialize Function :
Public Shared Function JSONDeserializeFreshDeskCie(repContent As Stream) As Customer
Dim rs As Customer = Nothing
Dim test As Object
Dim serializer As New JsonSerializer()
Try
Using sr As New StreamReader(repContent)
Using jsonTextReader As New JsonTextReader(sr)
rs = serializer.Deserialize(Of Customer)(jsonTextReader)
End Using
End Using
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
Return rs
End Function
Here where i call my function to retrieve my object :
Private Sub loadAllCie(ByVal e As IRestResponse)
Dim rep As Stream = Nothing
Dim rs As Customer
Try
rep = New MemoryStream(e.RawBytes())
If e.ErrorException IsNot Nothing OrElse e.StatusCode <> Net.HttpStatusCode.OK Then
Dim strError As String = ""
If e.ErrorException IsNot Nothing Then
strError = "Error : " & e.ErrorException.Message & vbCrLf
End If
strError &= "Web Error : " & e.ErrorMessage
strError &= vbCrLf & e.StatusCode.ToString()
MessageBox.Show(strError)
Exit Try
End If
rs = JSONSerialization.JSONDeserializeFreshDeskCie(rep)
Dim allo As String = ""
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If rep IsNot Nothing Then
rep.Close()
End If
End Try
End Sub
Look at the start of the JSON:
{"customer":{"created_at"...
There is an outer container created to hold "customer" which your code does not account for. If you do not want to create a do-nothing class for it, parse the result first:
Dim jstr = ...from whereever
Dim jobj = JObject.Parse(jstr)
Dim cust = JsonConvert.DeserializeObject(Of Customer)(jobj("customer").ToString)
To use a class:
Public Class CustContainer
Public Property customer As Customer
End Class
...
Dim cust = JsonConvert.DeserializeObject(Of CustContainer)(jstr)
I dont like the second because it requires all the rest of the references to be cust.customer.Foo, so I prefer to discard them.