Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserializing JSON list/array to C# classes
    primarykey
    data
    text
    <p>I am trying to deserialize the following into C# classes:</p> <pre><code>{ "response" : { "" : { "Expense" : [[{ "chart_of_accounts_id" : "45f2fd8f-68b2-44cc-b07ac031c97cd96c", "account_name" : "Salaries", "amount" : "1500.00", "entry_type" : "Debit", "business_id" : "528f00bb-8cd8-4e7f-be6a-0724c327a7be", "account_category" : "5" }, { "chart_of_accounts_id" : "45f2fd8f-68b2-44cc-b07ac031c97cd96c", "account_name" : "Salaries", "amount" : "200.00", "entry_type" : "Debit", "business_id" : "528f00bb-8cd8-4e7f-be6a-0724c327a7be", "account_category" : "5" } ]] } }, "messages" : { "msgs" : "", "errs" : "" } } </code></pre> <p>I have the following so far but I get the error "cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Systems.Collections.Generic.List'1[eko_app.Expenses+ExpensesResponse]' because it requires a JSON array (e.g. [1,2,3]) to deserialize correctly"</p> <pre><code>public class Expense { public string chart_of_accounts_id { get; set; } public string account_name { get; set; } public decimal amount { get; set; } public string entry_type { get; set; } public string business_id { get; set; } public int account_category { get; set; } } public class ExpensesResponse { public List&lt;Expense&gt; Expense { get; set; } } public class Messages { public string msgs { get; set; } public string errs { get; set; } } public class RootObject { public List&lt;ExpensesResponse&gt; response { get; set; } public Messages messages { get; set; } } // deserialize the json to c# .net var response = Newtonsoft.Json.JsonConvert.DeserializeObject&lt;RootObject&gt;(jsonData); if (response != null) { expenses = response.response; } </code></pre> <p>What should I do to correct this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload