Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
¿Cómo deserializar JSON con propiedades denominadas "1" y "2"? Estos no son nombres de propiedad válidos en C#

Estoy llamando a una API REST desde C# donde el nombre de la clase es un número, lo que no está permitido en C#. No estoy seguro de cómo puedo solucionar esto. Estoy usando Newtonsoft para la serialización.

Este es el JSON de mi API REST:

 { "customfield_10323": { "1": [ "com.atlassian.greenhopper.service.sprint.Sprint@2442b4ee[id=78,rapidViewId=21,state=CLOSED,name=APPLE A5 (27/07 - 07/08),startDate=2020-07-27T08:00:00.000+01:00,endDate=2020-08-07T17:00:00.000+01:00,completeDate=2020-08-13T11:22:53.314+01:00,sequence=78,goal=]", "com.atlassian.greenhopper.service.sprint.Sprint@54cfb92f[id=107,rapidViewId=19,state=ACTIVE,name=ORANGE B2 (08/03 - 19/03),startDate=2021-03-08T08:00:00.000Z,endDate=2021-03-19T17:00:00.000Z,completeDate=<null>,sequence=107,goal=]" ], "2": [ { "id": 78, "name": "APPLE A5 (27/07 - 07/08)", "state": "closed", "boardId": 21 }, { "id": 107, "name": "ORANGE B2 (08/03 - 19/03)", "state": "active", "boardId": 19 } ] } }

Que he traducido a esto:

 public class 2 { public int id { get; set; } public string name { get; set; } public string state { get; set; } public int boardId { get; set; } } public class Customfield10323 { public List<string> _1 { get; set; } public List<2> 2 { get; set; } } public class Root { public Customfield10323 customfield_10323 { get; set; } }

Pero no estoy seguro de que esto sea correcto porque no puedo llamar a la clase 2 porque viola las convenciones de nomenclatura. ¡Cualquier ayuda sería apreciada ya que estoy realmente atascado!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Modifique sus clases para usar el atributo JsonProperty :

 public class Two // valid class name { public int id { get; set; } public string name { get; set; } public string state { get; set; } public int boardId { get; set; } } public class Customfield10323 { [JsonProperty("1")] // property name in JSON public List<string> One { get; set; } // valid property name [JsonProperty("2")] // property name in JSON public List<Two> Two { get; set; } // valid property name } public class Root { public Customfield10323 customfield_10323 { get; set; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!