Я пытаюсь десериализовать json вот так
{
"geneslist": [
{
"seqid": "NC_045512.2",
"source": "RefSeq",
"type": "region",
"start": "1",
"end": "29903",
"score": ".",
"strand": "+",
"phase": ".",
"attributes": "ID=NC_045512.2:1..29903;Dbxref=taxon:2697049;collectiondate=Dec-2019;country=China;gbacronym=SARS-CoV2;gbkey=Src;genome=genomic;isolate=Wuhan-Hu-1;mol_type=genomic RNA;nathost=Homo sapiens;oldname=Wuhan seafood market pneumonia virus",
"ID": "NC_045512.2:1..29903",
"Note": null,
"Dbxref": "taxon:2697049",
"collectiondate": "Dec-2019",
"country": "China",
"gbacronym": "SARS-CoV2",
"gbkey": "Src",
"gene": null,
"inference": null,
"genome": "genomic",
"isolate": "Wuhan-Hu-1",
"locus_tag": null,
"gene_biotype": null,
"product": null,
"protein_id": null,
"mol_type": "genomic RNA",
"nathost": "Homo sapiens",
"oldname": "Wuhan seafood market pneumonia virus"
},
{
"seqid": "NC_045512.2",
"source": "RefSeq",
"type": "five_prime_UTR",
"start": "1",
"end": "265",
"score": ".",
"strand": "+",
"phase": ".",
"attributes": "ID=id-NC_045512.2:1..265;gbkey=5'UTR",
"ID": "id-NC_045512.2:1..265",
"Note": null,
"function": null,
"Dbxref": null,
"collectiondate": null,
"country;": null,
"gbkey": "5'UTR",
"Dbxrref": null,
"country": null,
"gbacronym": null,
"gene": null,
"inference": null,
"genome": null,
"isolate": null,
"locus_tag": null,
"gene_biotype": null,
"product": null,
"protein_id": null,
"mol_type": null,
"nathost": null,
"oldname": null
},{..} ]
}
, где некоторые данные могут быть нулевыми или существовать, я сделал для этого два объекта:
public class GenesList
{
private string seqid;
private string source;
private string type;
private int start;
private int end;
private string score;
private string strand;
private string phase;
private string attributes;
private string ID;
private string Note;
private string function;
private string Dbxref;
private string collectiondate;
private string country;
private string gbacronym;
private string gbkey;
private string gene;
private string inference;
private string genome;
private string isolate;
private string locus_tag;
private string gene_biotype;
private string product;
private string protein_id;
private string mol_type;
private string nathost;
private string oldname;
public string Seqid { get => seqid; set => seqid = value; }
public string Source {get => source; set => source = value; }
public string Type { get => type; set => type = value; }
public int Start { get => start; set => start = value; }
public int End { get => end; set => end = value; }
public string Score { get => score; set => score = value; }
public string Strand { get => strand; set => strand = value; }
public string Phase { get => phase; set => phase = value; }
public string Attributes { get => attributes; set => attributes = value; }
public string ID1 { get => ID; set => ID = value; }
public string Dbxref1 { get => Dbxref; set => Dbxref = value; }
public string Collectiondate { get => collectiondate; set => collectiondate = value; }
public string Country { get => country; set => country = value; }
public string Gbacronym { get => gbacronym; set => gbacronym = value; }
public string Gbkey { get => gbkey; set => gbkey = value; }
public string Genome { get => genome; set => genome = value; }
public string Isolate { get => isolate; set => isolate = value; }
public string Mol_type { get => mol_type; set => mol_type = value; }
public string Nathost { get => nathost; set => nathost = value; }
public string Oldname { get => oldname; set => oldname = value; }
public string Locus_tag { get => locus_tag; set => locus_tag = value; }
public string Gene_biotype { get => gene_biotype; set => gene_biotype = value; }
public string Function { get => function; set => function = value; }
public string Inference { get => inference; set => inference = value; }
public string Product { get => product; set => product = value; }
public string Protein_id { get => protein_id; set => protein_id = value; }
public string GetGene()
{
return gene;
}
public void SetGene(string value)
{
gene = value;
}
}
и
public class GenesWrapper
{
private List<GenesList> geneslist;
public List<GenesList> Genes { get => geneslist; set => geneslist = value; }
}
, но когда я пытаюсь выполнить десериализацию с помощью
GenesWrapper genesList = new GenesWrapper();
genesList = JsonConvert.DeserializeObject<GenesWrapper>(file2);
, я получаю исключение ArgomentNullException, потому что объект имеет значение null после десериализации, создал ли я плохой объект? Сначала я подумал, что у него могут быть проблемы с нулевыми значениями или, возможно, с порядком создания файла json. Я использовал NullValueHandling.Ignore
, но значения все еще равны нулю, как я могу решить? Простите за стенку текста, спасибо