I am trying to read my nested JSON result and I'm able to read the data from the first array. But not able to read from the remaining.
BELOW IS THE CODE WHICH GIVES THE RESULT FROM THE ORDER NODE
Fiddle: https://dotnetfiddle.net/biXBqd
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = @"{""orders"": [
{
""orderNumber"": ""12345"",
""orderDate"": ""2022-03-16"",
""status"": ""Completed"",
""state"": ""Completed"",
""description"": """",
""subs"": [
{
""subsNumber"": ""54321"",
""Managed"": null,
""customFields"": {},
""FirstVersion"": null,
""LastVersion"": 1,
""Actions"": [
{
""id"": ""abc"",
""sequence"": 0,
""TDates"": [
{
""Date"": ""2022-03-16""
},
{
""Date"": ""2022-03-16""
},
{
""Date"": ""2022-03-16""
}
]
}
]
}
],
""customFields"": {
""OrderDelivery"": null,
""DateOrderDelivered"": null
}
}
],
""nextPage"": ""/orders?page=4"",
""success"": true
}";
ArrayList profileAry1 = new ArrayList();
JObject jsonparsing1 = JObject.Parse(json);
JObject jsonparsing = JObject.Parse(json);
var token = (JArray)jsonparsing.SelectToken("orders");
List<string> AuthorList = new List<string>();
foreach (orders orders in JsonConvert.DeserializeObject<List<orders>>(token.ToString()))
{
string orderNumber = orders.orderNumber.ToString();
string orderDate = orders.orderDate.ToString();
string status = orders.status.ToString();
string state = orders.state.ToString();
string description = orders.description.ToString();
Console.WriteLine("Order Number: " + orderNumber);
Console.WriteLine("Order Number: " + orderDate);
Console.WriteLine("status: " + status);
Console.WriteLine("status: " + state);
Console.WriteLine("description: " + description);
Console.WriteLine();
}
PocoCourse items = JsonConvert.DeserializeObject<PocoCourse>(json);
Console.WriteLine("success: " + items.Success);
Console.WriteLine("Message: " + items.nextPage);
//Console.WriteLine("Number of Types: " + items.orders.Count);
}
}
public class PocoCourse
{
public bool Success { get; set; }
public string nextPage { get; set; }
public List<orders> orders { get; set; }
}
public class orders
{
public string orderNumber { get; set; }
public DateTime orderDate { get; set; }
public string status { get; set; }
public string state { get; set; }
public string description { get; set; }
public List<subs> subs { get; set; }
}
public class subs
{
[JsonProperty("subs")]
public string subsNumber { get; set; }
public string Managed { get; set; }
public string FirstVersion { get; set; }
public string LastVersion { get; set; }
//public List<subscriptions1> subscriptions { get; set; }
public List<List<object>> Points { get; set; }
}
I want to get the values from subs,Actions and TDates as well which I'm not able to achive.
Can anyone please help on this?