Ciao.
Ho una stringa formato json. Il mio obiettivo è fare il parsing di questa stringa, con Newtonsoft, senza classe ausiliaria e supponendo di non conoscerne la struttura.
Il codice di sotto sembra funzionare ma, a dire la verità non mi convince. Chiedo se si possa semplificare.
codice:Option Strict On Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Module Module1 Sub Main() Dim s As String = "{""nome"":""Pietro"", ""numero"":9.3, ""vettore"":[1, 2], ""testonull"":null, ""geometry"":{""x"":8.5,""y"":40.5},""attributes"":{""objectId"":1,""testo1"":null,""testo2"":""xxx"",""numero1"":null,""numero2"":44.6}}" Prova(s) Console.Write("Premere un tasto per continuare . . . ") : Console.ReadKey() End Sub Private Sub Prova(s As String) Dim o As JObject = JObject.Parse(s) For Each j In o.Children Dim value As JToken = Nothing Dim name As String = j.Path o.TryGetValue(name, value) Console.WriteLine("j.Path: {0}", j.Path) Console.WriteLine("o(j.Path).ToString: {0}", o(j.Path).ToString) Console.WriteLine("value.ToString: {0}", value.ToString) Console.WriteLine("value.Type: {0} ({1})", value.Type.ToString, CInt(value.Type)) Console.WriteLine() If value.Type = JTokenType.Object Then Prova(value.ToString) End If Next End Sub End Module

Rispondi quotando
la verità è che sono in ferie e non ho di meglio da fare che sperimentare 