0

What should be the class for de-serializing this json?

{
  "_attachments": {
    "Test.png": {
      "content_type": "application/octet-stream",
      "digest": "sha1-wGqfYwROlnGdNmiVIEpiTKHTm5I=",
      "length": 2461,
      "revpos": 10,
      "stub": true
    },
    "Test1.png": {
      "content_type": "application/octet-stream",
      "digest": "sha1-wGqfYwROlnGdNmiVIEpiTKHTm5I=",
      "length": 2461,
      "revpos": 11,
      "stub": true
    }
  },
  "_rev": "11-8fa68244426ebf7643d1c59c44dd0ae9",
  "_id": "a20191999c9e8372c577638ac9b8b205"
}

I tried with this class but I am not sure how to get the file names.

public class Attachment
{
    public string content_type { get; set; }
    public string digest { get; set; }
    public int length { get; set; }
    public int revpos { get; set; }
    public bool stub { get; set; }
}

public class Document
{
    string _id { get; set; }
    string _rev { get; set; }

    List<Attachment> _attachments { get; set; }
}

I am trying to convert back and forth a Couchbase document using the sync gateway REST API. When the attachments are to be handled I have issues in converting them the document to .net objects.

Vasu Inukollu
  • 120
  • 1
  • 3
  • 10
  • I think this will help you http://stackoverflow.com/questions/7895105/deserialize-json-with-c-sharp – Samvel Petrosov Nov 04 '16 at 09:25
  • try `dynamic` type if you are not sure what class you have to create or you have multiple nested json – Iftikhar Ali Ansari Nov 04 '16 at 09:29
  • The attachments are stored in properties of the document object, with the property name being the filename. To read that, you need to deserialize it into a `Dictionary`, which you can then iterate over. See [duplicate](http://stackoverflow.com/questions/34202496/parsing-json-object-with-variable-properties-into-strongly-typed-object). – CodeCaster Nov 04 '16 at 09:31
  • I read this later and fixed my problem. Thanks. http://stackoverflow.com/questions/29727345/deserialize-json-from-api-response?rq=1 – Vasu Inukollu Nov 04 '16 at 10:10

0 Answers0