Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear all,

In Visual Basic I have the code that I can get the company details by entering their VATnumber. Now the result I am getting is in 1 big json string. Now I have heard that VATlayer also can work with a JSONP Callbacks, this however, I can't seem to figure out how to put in the code so, I can get each result separated. That I can get for example the company name in a string, that I can use thru out the porgram.

Can anyone please help me with this?

The code I have is;
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
       Dim URLString = "http://apilayer.net/api/validate&vat_number=GB864438791"
       Try
           'Create the initial request
           Dim Request As HttpWebRequest = HttpWebRequest.Create(URLString)
           Request.Proxy = Nothing 'Speeds up the request by setting the proxy to nothing
           Request.UserAgent = "Test"

           'Create response and reader
           Dim Response As HttpWebResponse = Request.GetResponse
           Dim ResponseStream As System.IO.Stream = Response.GetResponseStream

           'Create a new streamreader
           Dim StreamReader As New System.IO.StreamReader(ResponseStream)
           Dim Data As String = StreamReader.ReadToEnd

           UrlResponseText.Text = Data
           StreamReader.Close()

       Catch ex As Exception
           MsgBox("Improper Input")
           GoURL.Text = Nothing
       End Try

          End Sub


The the result is shown like;
Result from streamreader;
        '{"valid":true,"database":"ok","format_valid":true,"query":"GB864438791","country_code":"GB","vat_number":"864438791","company_name":"EXERTIS (UK) LTD","company_address":"TECHNOLOGY HOUSE\nMAGNESIUM WAY\nHAPTON\nBURNLEY\n\nBB12 7BF"}


An I would like to see that I can assign all the result value to separated strings.

Thanks,
Hans

P.s.

This VAT layer requires a key to enter in the string. So this URL will not work. Like this. But with key you get the below shown result,

What I have tried:

I have search the internet and tried using
New JavaScriptSerializer().Deserialize(Of List(Of Object))(Data)
.
Posted
Updated 2-Nov-19 7:28am
v4
Comments
Richard MacCutchan 2-Nov-19 11:58am    
You need to use a JSON deserialiser, not JavaScript. See JSON deserialiser vb.net - Google Search[^].
Richard Deeming 5-Nov-19 16:03pm    
NB: JavaScriptSerializer is the old built-in JSON (de)serializer. :)
JavaScriptSerializer Class (System.Web.Script.Serialization) | Microsoft Docs[^]
Richard MacCutchan 6-Nov-19 3:43am    
:thumbsup: more reading for me.

1 solution

Example:
http://apilayer.net/api/validate?callback=CALLBACK_FUNCTION[^]

You can find the documentation about JSONP Callbacks here: Documentation | vatlayer API[^]

You can generate a class for the JSON response here: JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]
Public Class Example
        Public Property valid As Boolean
        Public Property database As String
        Public Property format_valid As Boolean
        Public Property query As String
        Public Property country_code As String
        Public Property vat_number As String
        Public Property company_name As String
        Public Property company_address As String
    End Class
 
Share this answer
 
v2
Comments
Member 13039327 3-Nov-19 7:55am    
Hello RickZeeland,

Thank you very much for your help. It does look very promissing. However, as I reached my limits at vatlayer, I can't try for now. But when I can, I will let you kmow the outcome.

Regards,
Hans

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900