allora, questo mi da l'errore di prima (Non è possibile convertire il valore di tipo 'List(Of Book)' in 'Book'):
codice:
Dim list As List(Of Book) = JsonConvert.DeserializeObject(Of Book)(json)
se faccio così:
codice:
Dim list As Book = JsonConvert.DeserializeObject(Of Book)(json)
ottengo questo:
codice:
Eccezione non gestita: Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'VBTest.Book' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
in Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
in Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
in Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
in Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
in VBTest.Module1.VB$StateMachine_1_SendRequest.MoveNext() in C:\VS_Proj\VBTest\VBTest\Module1.vb:riga 23
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
in System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
in System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
in System.Threading.ThreadPoolWorkQueue.Dispatch()
in System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
considerando che la struttura del JSON è questa:
codice:
[
{...},
{...},
]