0

I'm using the Freeagent API and need a way to convert the JSON to .Net types. Using JSON .Net I need to convert the following JSON to IEnumerable

{ "invoices": [
  {
    "url":"https://api.freeagent.com/v2/invoices/1",
    "contact":"https://api.freeagent.com/v2/contacts/2",
    "dated_on":"2011-08-29T00:00:00+00:00",
    "due_on":"2011-09-28T00:00:00+00:00",
    "reference":"001",
    "currency":"GBP",
    "exchange_rate":"1.0",
    "net_value":"0.0",
    "sales_tax_value":"0.0",
    "status":"Draft",
    "comments":"An example invoice comment."
    "omit_header":false,
    "payment_terms_in_days":30,
    "ec_status":"Non-EC"
  }
]}

Now I dont want to use a base type if I can avoid it so I'm looking to directly Deserialize this to the IEnumerable above. Is it possible?

LiamB
  • 18,243
  • 19
  • 75
  • 116
  • Could you post some sample-code? Maybe Freeagent has got an overload to bypass a target type? Why not JSON.NET? Direct cast? – Alexander Schmidt Jan 29 '13 at 11:27
  • You should have a look at this question: [Deserialize JSON into C# dynamic object?](http://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object) – Yannick Blondeau Jan 29 '13 at 11:40
  • @YannickBlondeau That shows me how to convert to Dynamic. Json.Net supports that dynamically. I need to convert to an object. – LiamB Jan 29 '13 at 11:53
  • @sprinter252 Direct Cast to IEnumerable doesn't work. – LiamB Jan 29 '13 at 11:53
  • I can pull it out as a Dynamic object then use reflection to cast it. But was hoping there was a simpler way. – LiamB Jan 29 '13 at 11:54

0 Answers0