以下JSON字符串的正确语法是什么

niwlg2el  于 2023-02-17  发布在  其他
关注(0)|答案(2)|浏览(147)

我需要从MSACCES数据库中提取JSON对象中的数据......所以我不太确定正确的JSON字符串语法。

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

或者这个

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

我想知道是{"国家":[{"网络...还是{"国家":{"网络...

lstz6jyr

lstz6jyr1#

因为你有一个Country[]数组,我建议你把你的Country键重命名为Countries

Countries: [{}, {}]
o4tp2gmn

o4tp2gmn2#

恕我直言,最好的办法就是保持关系

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

类(翻译成您的语言)

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; }
    }

相关问题