skip to Main Content

I need to extract data from MSACCES database in JSON object…
So I’m not quite sure about the right JSON string syntax.
Which one is correct:

{
  "Continent": {
    "Europe": {
      "Countries": 
        {
          "The Netherlands": {
            "Cities": [
              "Rotterdam",
              "Hag",
              "Amsterdam"
            ]
          }
        },
        {
          "Germany": {
            "Cities": [
              "Bon",
              "Berlin"
            ]
          }
        }
    }
  }
}

or this one:

{
  "Continent": {
    "Europe": {
      "Countries": [
        {
          "The Netherlands": {
            "Cities": [
              "Rotterdam",
              "Hag",
              "Amsterdam"
            ]
          }
        },
        {
          "Germany": {
            "Cities": [
              "Bon",
              "Berlin"
            ]
          }
        }
      ]
    }
  }
}

I wonder between {"Countries":[{"The Net… or {"Countries":{"The Net..

2

Answers


  1. Since you are having an array of Country[], I would advice you to rename your Country key by Countries:

    Countries: [{}, {}]
    
    Login or Signup to reply.
  2. IMHO, the best way is to keep relations

    {
      "Continens": {
        "Continent": "Europe",
        "Countries": [
          {
            "Country": "The Netherlands",
            "Cities": [
              "Rotterdam",
              "Hag",
              "Amsterdam"
            ]
          },
          {
            "Country": "Germany",
            "Cities": [
              "Bon",
              "Berlin"
            ]
          }
        ]
      }
    }
    

    classes (translate to your language)

     public class World
        {
            public Continens Continens { get; set; }
        }
         public class Continens
        {
            public string Continent { get; set; }
            public List<Country> Countries { get; set; }
        }
    
        public class Country
        {
            public string Country { get; set; }
            public List<string> Cities { get; set; }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search