1

I'm currently using Microsoft.AspNet.WebApi.Client 5.0.0 which includes Newtonsoft.Json 4.5.11. My solution is in VS 2012 and .Net 4.5. I'm making a REST call to Box.com (External call... I have no control over the json content). From the following (trimmed-down) response Json, I want to deserialize the "entries" array into strongly typed "folder" and "file" objects, based on the value of the "type" property in the response. I'm trying to avoid any custom conversion. Is there a straight forward way to do this, perhaps with attributes? I feel I'm missing something simple.

{
    "total_count" : 2,
    "entries" : [{
                   "type" : "folder",
                   "id" : "12345678",
                   "sequence_id" : "2",
                   "etag" : "2",
                   "name" : "Some Folder",
                },

                {
                   "type" : "file",
                   "id" : "4324348834",
                   "sequence_id" : "8",
                   "etag" : "8",
                   "sha1" : "134324329e9k93kdieoikek",
                   "name" : "Testing.xlsx",
                   "description" : "",
                   "item_status" : "active"
                }
    ],
    "limit" : 30,
    "offset" : 0
}
ICS
  • 83
  • 9
  • What version of VS/.NET are you using? I believe you will have to do some custom conversion but some use of the [`dynamic`](http://msdn.microsoft.com/en-us/library/dd264736.aspx) keyword could alleviate a lot of the headache (using a `Dictionary` as the backing store). – Erik Jan 17 '14 at 21:21
  • @Brad... That answer appears to be A solution, but does not appear definitive about whether there's a non-custom way to do it. Is the use of JSON.NET a limiting factor here? Is there a better library to use to simplify it? This just seems pretty basic to have to write custom convertors. – ICS Jan 17 '14 at 21:31

0 Answers0