Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deserialize json with class name as dynamic values
    text
    copied!<p>How can I De-serialize following json?</p> <pre><code>{ "data": { "11396": { "description": "Timer project", "status": "ACTIVE", "customer": { "locations": {}, "id": 96626 }, "tasks": [ { "description": "Timer Task", "unit": "h", "vatPct": 0.2, "unitPrice": 12, "billable": true, "id": 19660 } ], "price": 0, "pricing": "UNIT", "allowProducts": true, "hasUninvoicedItems": false, "id": 11396 }, "11397": { "description": "Timer Project 2", "status": "ACTIVE", "customer": { "locations": {}, "id": 96626 }, "tasks": [ { "description": "Timer Task2", "unit": "h", "vatPct": 0.05, "unitPrice": 20, "billable": true, "id": 19655 } ], "price": 0, "pricing": "UNIT", "allowProducts": true, "hasUninvoicedItems": false, "id": 11397 } }, "ok": true } </code></pre> <p>The problem is that values 11396, 11397 as class name (if convert to c#) which are actually ids of that particular record. so when converting this json to c# using <a href="http://json2csharp.com" rel="nofollow">http://json2csharp.com</a>. it shows as this</p> <pre><code>public class Locations { } public class Customer { public Locations locations { get; set; } public int id { get; set; } } public class Task { public string description { get; set; } public string unit { get; set; } public double vatPct { get; set; } public double unitPrice { get; set; } public bool billable { get; set; } public int id { get; set; } } public class __invalid_type__11397 { public string description { get; set; } public string status { get; set; } public Customer customer { get; set; } public List&lt;Task&gt; tasks { get; set; } public double price { get; set; } public string pricing { get; set; } public bool allowProducts { get; set; } public bool hasUninvoicedItems { get; set; } public int id { get; set; } } public class Locations2 { } public class Customer2 { public Locations2 locations { get; set; } public int id { get; set; } } public class Task2 { public string description { get; set; } public string unit { get; set; } public double vatPct { get; set; } public double unitPrice { get; set; } public bool billable { get; set; } public int id { get; set; } } public class __invalid_type__11396 { public string description { get; set; } public string status { get; set; } public Customer2 customer { get; set; } public List&lt;Task2&gt; tasks { get; set; } public double price { get; set; } public string pricing { get; set; } public bool allowProducts { get; set; } public bool hasUninvoicedItems { get; set; } public int id { get; set; } } public class Data { public __invalid_type__11397 __invalid_name__11397 { get; set; } public __invalid_type__11396 __invalid_name__11396 { get; set; } } public class RootObject { public Data data { get; set; } public bool ok { get; set; } } </code></pre> <p>any help is much appreciated.</p>
 

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