How to read Json data using List<T> in c#

  • Thread starter Thread starter Narayana Reddy GundReddy
  • Start date Start date
N

Narayana Reddy GundReddy

Guest
Dear all,

I've the following Json format and would like to read items under menu using List<T> in c#. I am able to read menu but not able to find a way to read items. Please share your ideas. I appreciate your help and thank you very much!

I am using the following code and not able to declare the datatype to store items collection in the APIData class (I created), declared string data type in the APIData class to read menu:

==========================================================================

HttpResponseMessage responseMessage = client.GetAsync(url).Result;
if (responseMessage.IsSuccessStatusCode)
{
var responseData = responseMessage.Content.ReadAsStringAsync().Result;
var list = JsonConvert.DeserializeObject<List<APIData>>(responseData);
foreach (var data in list)
{

string menu = data.menu;
}

}

======================================================================================================

public class APIData
{
public string menu { get; set; }

}
==========================================================================

Json Format:

[

{
"$id": "1",
"Id": "99a08d4b-8e20-4811-beee-1b56ac545f90",
"menu": "Menu 04",
"items": [
{
"$id": "2",
"Id": "90ed4d57-7921-4c66-b208-4e312a9852e6",
"Name": "Paprika Sausage",
"Length": 6,
"Width": 3,
"Duration": "00:08:00",
"Quantity": 40
},
{
"$id": "3",
"Id": "47614f4d-2621-40de-8be7-e35abed8ed44",
"Name": "Veal",
"Length": 8,
"Width": 4,
"Duration": "00:08:00",
"Quantity": 10
}
]
}
]

===============================================================


Narayana Reddy G

Continue reading...
 
Back
Top