il post e' visibile.
Semplicemente, il JSON rappresenta un array di persone, ma è strano.
Stavo usando le classi:
codice:public class containerRamiRete { public out_ramoRete ramo { get; set; } } public class out_ramoRete { public IList<nodoRete> listaAgenti { get; set; } } public class nodoRete { public string UTERET_profilo_rete_comm { get; set; } public string DTAIAR_data_da { get; set; } public string DTAFAR_data_a { get; set; } public string QALRET_qualifica_rete { get; set; } public string CDCLAR_cod_controparte { get; set; } public string ndg_cdclar { get; set; } public string RASOC_ragione_sociale { get; set; } public string FILARE_filiale { get; set; } public string CDLIAR_cod_controp_liquid { get; set; } public string ndg_cdliar { get; set; } public string UTPDAR_utente_padre { get; set; } public string ndg_utpdar { get; set; } public string GRURET_gruppo_appartenenza { get; set; } public string AIREC_abilitato_caricamento { get; set; } public string ACFRE_abilitato_caricamento_figli { get; set; } public string dataRif { get; set; } public string XCDRES_responsabile { get; set; } public string listaProdottiAbilit { get; set; } // [CA”,”CB”,”DA”] // prodotti abilitati public string obbligoFinanziato { get; set; } }
ma alle istruzioni:
codice:// PROVA 1 ----------------------------------------------------------------------------------------- // aaaa contiente un oggetto di tipo <out_ramoRete> = NULL List<out_ramoRete> nodo1 = JsonConvert.DeserializeObject<List<out_ramoRete>>(dati); // PROVA 2 ----------------------------------------------------------------- //Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ApiClient2.nodoRete]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. //To fix this error either change the JSON to a JSON array(e.g. [1, 2, 3]) or change the deserialized type so that it is a normal .NET type(e.g.not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object.JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. //Path 'IFAGE00201', line 1, position 14.' List<nodoRete> nodo2 = JsonConvert.DeserializeObject<List<nodoRete>>(dati);
....Restituiva gli errori che ho riportato commentati sopra l'istruzione.
Poi, grazie a StackOverflow, ho incontrato: https://json2csharp.come l'ho fatto funzionare.
Vedo che il tuo esempio è preso da li' (ero da 3 giorni e sono contemporaneamente arrivato alla soluzione).
Ho solo alcuni dubbi, poi li chiariro' con la software house che ha sviluppato le API.
Grazie.
Ah, un'altra istruzione funzionava, provala:
codice:// restituisce un Newtonsoft.Json.Linq.JObject dynamic ramoreteOut = JsonConvert.DeserializeObject(dati);
ma non sapevo maneggiare l'oggetto di ritorno (Newtonsoft.Json.Linq.JObject ??)

e l'ho fatto funzionare.
Rispondi quotando