1

I'm having this Json-data as a document in ravenDb, but I don't know how to model my c#-class/classes in my MVC 5 application to get it to work. Can someone please point me in the right direction. Thanks.

{
  "Name": "Finland",
  "Code": "4234",
  "Area": 25453,
  "Capital": "324234",
  "Province": "sfdfsf",
  "FlagId": "34",
  "ContinentCode": "6554",
  "ShipTo": {
      "Line1": "2817 Milton Dr.",
      "Line2": null,
      "City": "Albuquerque",
      "Region": "NM",
      "PostalCode": "87110",
      "Country": "USA"
   }
}
user3228992
  • 1,373
  • 1
  • 16
  • 31
  • 3
    Try [json2csharp](http://json2csharp.com/), or just use the ["Paste JSON As Classes"](http://blogs.msdn.com/b/webdev/archive/2012/12/18/paste-json-as-classes-in-asp-net-and-web-tools-2012-2-rc.aspx) feature in Visual Studio. – Matt Johnson-Pint Apr 12 '14 at 18:58

1 Answers1

0

Basic definition is as follows. I've assumed anything in quotes is a string, although they contain integers. I think the JsonDeserializer will work with this, but just being safe:

// TODO: Change class name to reflect document name
public class ShipToDetails
{
   public string Id { get; set; }
   public string Name { get; set; }
   public string Code { get; set;

   public int Area { get; set; }
   public string Capital { get; set; }
   public string Province { get; set; }
   public string FlagId { get; set; }
   public string ContinentCode { get; set; }

   public Address ShipTo { get; set; }
}

public class Address
{
   public string Line1 { get; set; }
   public string Line2 { get; set; }
   public string City { get; set; }
   public string Region { get; set; }
   public string PostalCode { get; set; }
   public string Country { get; set; }
}
Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61