Search code examples
c#multidimensional-arrayajaxform

C# looping array object multidimensional from ajax post


I have Multidimensional array object How to loop all value in c# ? in C#

charge[0]{[ChargeMultiId, da95aad9-0cdc-40bb-a5db-3bc0933dea4a ]}
charge[1]{[ChargeMultiNoteslist, Testing notes 29/04/2016 ]}
charge[22]{[Diagnosis, : ["1", "2", "3", "4", "5", "6", "7", "8", "9"]}

Ajax

    charge =
    "ChargeMultiId": "da95aad9-0cdc-40bb-a5db-3bc0933dea4a",
    "ChargeMultiNoteslist": "Testing notes 29/04/2016",
    "ChargeMultiCode": "99238",
    "ChargeMultiCodeName": "HOSP DSCHRG D MGMT 30 MIN/ < > & '",
    "ChargeMultiProcedureID": "89c5ecaf-903b-41d7-8564-e4034d94934f",
    "Diagnosis": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
}, {}
]

Solution

  • I think you should make the model class as below.

    public class Charge 
    { 
         public Guid ChargeMultiId { get; set; }
         public string ChargeMultiNoteslist { get; set; }
         public int ChargeMultiCode { get; set; }
         public string ChargeMultiCodeName { get; set; }
         public Guid ChargeMultiProcedureID { get; set; }
         public List<int> Diagnosis { get; set; }
    }
    

    Install Newtonsoft.Json using below command (In NuGet package manager).

    Install-Package Newtonsoft.Json
    

    To deserialize your JsonString to Object List as below.

    List<string> listOfObjects = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Charge>>(yourJsonStringHere);
    

    For more Information about Newtonsoft.Json Please visit below link.

    http://www.newtonsoft.com/json/help/html/Introduction.htm