Q:

Extract Array of Strings from JSON in Visual Basic

I'm a little bit of a newbie in Visual Basic.  I'm downloading some data from a web API.  The data arrives to me in JSON format.  My main problem is that sometimes the data is a string and sometimes it's an array of strings. Here you can see an example:    
Texto = "{""1"":[""Trova Tutto""], 
          ""3"":""Tutta Sulla Tua Ricerca"",  
          ""4"":""Trova Qui"",  
          ""5"":[""https://www.smarter.com/it/ar?Trova+Tutto&q={keyword}"", ""delicious_potatoes""]}" 

I would like to be able to know when the value is an array or not. If it's an array I would like to extract each of the values and store them in the return variable (retorno)
I've tried to extract the data from the variable elemento.First, but I wasn't able to determine whether the data is an array or a string.  Also I tried to deserialize it, but that didn't work either.
Here is my VB code:
Public Shared Function getCustomParametersV2(texto As String) As Dictionary(Of String, Dictionary(Of String, String))
    Dim retorno As New Dictionary(Of String, Dictionary(Of String, String))
    Dim counter As New Integer
    Dim dict As Object
    Try
        If texto.Trim <> "--" Then
            Dim json As JObject = JObject.Parse(texto)
            For Each elemento In json.Children
                ' en el caso de que sea un array lo recorremos y unimos en un unico string
                'dict = JsonConvert.DeserializeObject(Of List(Of Object))(elemento.First)
                If IsArray(elemento.First) Then
                    counter = 0
                    For Each cosita In elemento.First
                        retorno.Add(elemento.Path, New Dictionary(Of String, String) From {{counter.ToString(), cosita}})
                        counter += 1
                    Next
                End If
                retorno.Add(elemento.Path, New Dictionary(Of String, String) From {{1, elemento.First}})
            Next
        End If
    Catch ex As Exception
        If Not retorno.ContainsKey("error") Then
            texto = texto.Replace("""", String.Empty)
            If texto.Length > 50 Then texto = texto.Substring(0, 50)
            retorno.Add("error", New Dictionary(Of String, String) From {{1, texto}})
        End If
    End Try

    Return retorno
End Function

I would like to extract the information that was shown before, but I don't know how make it so that my code notices when it is an array and when it's not and extract the values accordingly.
Finally, I would like to have the following dict:
retorno = {
           "1" : {"0": "Trova Tutto"}
           "3" : {"0": "Tutta Sulla Tua Ricerca"}
           "4" : {"0": "Trova Qui"}
           "5" : {"0": "https://www.smarter.com/it/ar?Trova+Tutto&q={keyword}"
           "5" : {"1": "delicious_potatoes" }
         }

A:

First a clarification on your desired result.  The keys of a dictionary must be unique, so you cannot actually have two 5 keys in the result dictionary.  But I notice your function returns a Dictionary(Of String, Dictionary(Of String, String)), so I think what you actually meant was this:
{
   "1": { "0": "Trova Tutto" }
   "3": { "0": "Tutta Sulla Tua Ricerca" }
   "4": { "0": "Trova Qui" }
   "5": {
          "0": "https://www.smarter.com/it/ar?Trova+Tutto&q={keyword}",
          "1": "delicious_potatoes"
        }
}

If that is the case then we can proceed.
The Children of a JObject are JProperties.  You can use the Children(Of T) generic overload to ensure the loop variable is cast to the correct type.  Each JProperty has a Name and a Value, the latter of which is some type of JToken (in your case either a JValue representing a string or a JArray representing an array of strings).  To determine whether the token is an array or not you can check it's Type property.  If the type is JTokenType.Array then you'll want to add all of the array values to an inner dictionary (as opposed to adding each value to a new dictionary like you are doing now).
The code should look like this:
            Dim json As JObject = JObject.Parse(texto)
            For Each prop In json.Children(Of JProperty)()
                Dim innerDict As New Dictionary(Of String, String)
                If prop.Value.Type = JTokenType.Array Then
                    Dim counter As Integer = 0
                    For Each child In prop.Value.Children(Of JValue)
                        innerDict.Add(counter.ToString(), CStr(child))
                        counter += 1
                    Next
                Else
                    innerDict.Add("0", CStr(prop.Value))
                End If
                retorno.Add(prop.Name, innerDict)
            Next

Here is a working demo: https://dotnetfiddle.net/pQjhoy

