VB.NET og C# er jo det samme bare med lidt forskellig syntax.
Imports System
Imports System.Net
'
'Hoejre klik paa 'References' i 'Solution Explorer'
'Tryk paa 'Add reference'
'Oeverst i hoejre hjoerne soeger du blot efter 'web.extensions'
'System.Web.Extensions skal tilfoejes som reference.
'
Namespace cvropslag
Public Class Program
Public Shared Sub Main(args As String())
Dim company As ApiResult = GetCompanyInfo("10150817")
Console.WriteLine("Test: " & company.Name & " - " & company.Version)
Console.ReadLine()
End Sub
Public Class ApiOwners
Public Property Name() As String
End Class
Public Class ApipPoductionunits
Public Property Pno() As String
Public Property Name() As String
Public Property Address() As String
Public Property Zipcode() As String
Public Property City() As String
Public Property [protected]() As Boolean
Public Property Phone() As String
Public Property Email() As String
Public Property Fax() As String
Public Property Startdate() As String
Public Property Enddate() As String
Public Property Employees() As String
Public Property Addressco() As String
Public Property Industrycode() As Integer
Public Property Industrydesc() As String
Public Property Companycode() As Integer
Public Property Companydesc() As String
Public Property Creditstartdate() As String
Public Property Creditstatus() As System.Nullable(Of Integer)
Public Property Creditbankrupt() As Boolean
End Class
Public Class ApiResult
Public Property VAT() As String
Public Property Name() As String
Public Property Address() As String
Public Property Zipcode() As String
Public Property City() As String
Public Property [protected]() As Boolean
Public Property Phone() As String
Public Property Email() As String
Public Property Fax() As String
Public Property Startdate() As String
Public Property Enddate() As String
Public Property Employees() As String
Public Property Addressco() As String
Public Property Industrycode() As Integer
Public Property Industrydesc() As String
Public Property Companycode() As Integer
Public Property Companydesc() As String
Public Property Creditstartdate() As String
Public Property Creditstatus() As System.Nullable(Of Integer)
Public Property Creditbankrupt() As Boolean
Public Property Owners() As ApiOwners()
Public Property Productionunits() As ApipPoductionunits()
Public Property T() As Integer
Public Property Version() As Integer
End Class
Public Shared Function GetCompanyInfo(name As String) As ApiResult
Dim res As ApiResult
Using webClient = New WebClient()
webClient.Headers("User-Agent") = "mit projekt"
Dim resultContent As String = webClient.DownloadString(String.Format("
http://cvrapi.dk/api?search={0}&country=dk", name))
res = New System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(Of ApiResult)(resultContent)
End Using
Return res
End Function
End Class
End Namespace