C# looping array object multidimensional from ajax post
Asked Answered
G

1

0

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"]
}, {}
]
Gaol answered 7/6, 2017 at 6:54 Comment(5)
This is a JSON data format, you need to de-serialize it to your object typeTeillo
You might want to start with this: nuget.org/packages/Newtonsoft.JsonSteve
make sure your web service accept list of that object. Everything will be handled. Say your method is Charge(string chargeArray) convert this to Charge(List<Charge> charge)Carolanncarole
Please read #14640528.Billy
#39462018 look at thisDemagogue
B
1

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

Blatman answered 7/6, 2017 at 7:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.