Certo! Di seguito trovi un esempio di come potresti rappresentare l’oggetto JSON che hai fornito come una lista di oggetti in C#. Per farlo, è importante definire delle classi che riflettano la struttura dati, quindi creare una lista contenente un'istanza dell'oggetto.
Ecco un possibile esempio completo:
using System;
using System.Collections.Generic;
public class RootObject
{
public Id _id { get; set; }
public int ReaderType { get; set; }
public List<AooConservationInfo> ListAooConservationInfo { get; set; }
public bool IsRetrieve { get; set; }
public bool IsComplete { get; set; }
}
public class Id
{
public string $oid { get; set; }
}
public class AooConservationInfo
{
public string AooArxCeId { get; set; }
public string AooIXCeId { get; set; }
public List<Conservazione> Conservazioni { get; set; }
public List<Manuale> Manuali { get; set; }
}
public class Conservazione
{
public string IdAoo { get; set; }
public string IdentificativoCons { get; set; }
public string Nome { get; set; }
public string Descrizione { get; set; }
public string RootUri { get; set; }
public string Uri { get; set; }
public string NomeFile { get; set; }
public string UriFirmato { get; set; }
public string NomeFileFirmato { get; set; }
public string UriMarcato { get; set; }
public string NomeFileMarcato { get; set; }
public string UriFileMetadati { get; set; }
public string NomeFileMetadati { get; set; }
public string UriFileXsd { get; set; }
public string NomeFileXsd { get; set; }
public int NumeroDocumenti { get; set; }
public string HashMarcato { get; set; }
public int SincroXmlVersion { get; set; }
public int IdConfigurazioneClasse { get; set; }
public DateWrapper DataCreazione { get; set; }
public DateWrapper MaxDataConservazione { get; set; }
}
public class DateWrapper
{
public DateTime $date { get; set; }
}
public class Manuale
{
public string NomeFile { get; set; }
public string UriFile { get; set; }
public string HashFile { get; set; }
public string RootUri { get; set; }
}
public class Program
{
public static void Main()
{
List<RootObject> lista = new List<RootObject>()
{
new RootObject
{
_id = new Id { $oid = "67f66f6a9925bc4e58ee1385" },
ReaderType = 0,
ListAooConservationInfo = new List<AooConservationInfo>()
{
new AooConservationInfo
{
AooArxCeId = "4",
AooIXCeId = "55820ddf-b062-4ba3-9dc6-8d80fa163daa",
Conservazioni = new List<Conservazione>()
{
new Conservazione
{
IdAoo = "4",
IdentificativoCons = "0004fea5-be5a-496c-98bb-a69896681755",
Nome = "XX2",
Descrizione = "XX2",
RootUri = @"C:\ARXCE\DATA",
Uri = @"Conservazioni\4\2022\0004fea5be5a496c98bba69896681755",
NomeFile = "IDC_0004fea5be5a496c98bba69896681755.xml",
UriFirmato = @"Conservazioni\4\2022\0004fea5a496c98bba69896681755",
NomeFileFirmato = "IDC_0004fea5a496c98bba69896681755.xml.p7m",
UriMarcato = @"Conservazioni\4\2022\0004fea5a496c98bba69896681755",
NomeFileMarcato = "IDC_0004fea5a496c98bba69896681755.xml.p7m.tsd",
UriFileMetadati = @"Conservazioni\4\2022\0004fea5a496c98bba69896681755",
NomeFileMetadati = "Bolla.xml",
UriFileXsd = @"Conservazioni\4\2022\0004fea5a496c98bba69896681755",
NomeFileXsd = "Bolla.xsd",
NumeroDocumenti = 3,
HashMarcato = "eff360daa66ac3eee8aff52a5ad3f761ad1607b67c595f15bc96e6fedbf9de46",
SincroXmlVersion = 1,
IdConfigurazioneClasse = 3,
DataCreazione = new DateWrapper { $date = DateTime.Parse("2022-01-28T12:29:56Z").ToLocalTime() },
MaxDataConservazione = new DateWrapper { $date = DateTime.Parse("2022-01-30T23:00:00Z").ToLocalTime() },
}
},
Manuali = new List<Manuale>()
{
new Manuale
{
NomeFile = "Mandato_AOOMAURODEV_v1.xml",
UriFile = @"ManualiAoo\4",
HashFile = "fdeae4c9a0a9fa97d5ec2e2452fee17c3c45b01e20f988dc4c8add2b6774082d",
RootUri = @"C:\ARXCE\DATA"
},
new Manuale
{
NomeFile = "ManualeConservazioneSostitutiva.xml",
UriFile = "ManualiAoo",
HashFile = "fdeae4c9a0a9fa97d5ec2e2452fee17c3c45b01e20f988dc4c8add2b6774082d",
RootUri = @"C:\ARXCE\DATA"
}
}
}
},
IsRetrieve = true,
IsComplete = true
}
};
}
}
Spiegazioni
- Ho definito tutte le classi necessarie per corrispondere ai campi presenti nel JSON.
- Per i campi data che in JSON hanno la struttura
{"$date": "data"}, ho creato la classe DateWrapper per riflettere questa struttura.
- Nella definizione del percorso Windows ho usato la verbatim string (in eccesso in questo caso ma migliora la leggibilità).
- La lista finale
lista contiene un solo elemento inizializzato con i dati forniti.
Se vuoi solo il codice di inizializzazione della lista con l’oggetto, senza classi, dimmelo e te lo preparo!