-1

This is how the JSON Array looks:

[
{
"label": "google.com",
"value": "google.com"
},
{
"label": "google.co.in",
"value": "google.co.in"
},
{
"label": "google.de",
"value": "google.de"
},
{
"label": "google.co.uk",
"value": "google.co.uk"
},
{
"label": "google.co.jp",
"value": "google.co.jp"
},
{
"label": "google.fr",
"value": "google.fr"
},
{
"label": "google.com.br",
"value": "google.com.br"
},
{
"label": "google.ru",
"value": "google.ru"
},
{
"label": "google.it",
"value": "google.it"
},
{
"label": "google.es",
"value": "google.es"
}
]

I need to take the "value": or "label:" thingy and create an array in VB.net that'll contain their text.

google.com google.co.in etc. etc.

I have the JSON.Net library..

  • I've tried nothing yet, cuz samples in json.net documentation are all in C++ or c# so i'm asking you guys here. I mean this array should be simple to read :) – Bernard Berny Kozarić Aug 17 '14 at 17:43
  • Ah, well I'm afraid that this is not really a code writing service. Sadly. There are hundreds (if not thousands) of examples of simple JSON deserializatrion around using JSON.Net and others like the JavaScriptSerialiser (my favourite). May I suggest you try one of them out and then tailor to your specific case. If you have something specific that you've got a question about then come back and post it here. – Ciarán Aug 17 '14 at 17:50
  • the internet is filled with free C# to VB.NET converters. Try one. [This code](http://stackoverflow.com/a/24270278/1070452) uses JSON to create a NET Dictionary (a kind of an array professionals use) – Ňɏssa Pøngjǣrdenlarp Aug 17 '14 at 17:51
  • A clue though... while this is very simple JSON it is in fact an array of separate JSON objects. Good luck – Ciarán Aug 17 '14 at 17:54
  • Still don't know how to do it? Can anyone give me the code. This arrays is so simple :/ And I can't find a solution after hours of search – Bernard Berny Kozarić Aug 17 '14 at 18:32

1 Answers1

0

Made this class:

Class Product
    Public Value As String
End Class

Used this code:

Try
    TextBoxX1.AutoCompleteCustomSource.Clear()
Catch ex As Exception
End Try

Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.alexa.com/wwwdata/autocomplete?q=" & TextBoxX1.Text & "&limit=10")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim sourcecode As String = sr.ReadToEnd()
Dim products As List(Of Product) = JsonConvert.DeserializeObject(Of List(Of Product))(sourcecode)

For Each SiteName As Product In products
    TextBoxX1.AutoCompleteCustomSource.Add(SiteName.Value)
Next