What is the proper syntax of the following JSON string

huangapple go评论93阅读模式
英文:

What is the proper syntax of the following JSON string

问题

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...

英文:

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..

答案1

得分: 1

由于您拥有一个Country[]数组,我建议将您的Country键重命名为Countries

Countries: [{}, {}]
英文:

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

Countries: [{}, {}]

答案2

得分: 0

以下是翻译好的部分:

IMHO,最好的方法是保持关系

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

classes(翻译成您的语言)

{
    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; }
}
英文:

IMHO, the best way is to keep relations

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

classes (translate to your language)

 public class World
    {
        public Continens Continens { get; set; }
    }
     public class Continens
    {
        public string Continent { get; set; }
        public List&lt;Country&gt; Countries { get; set; }
    }

    public class Country
    {
        public string Country { get; set; }
        public List&lt;string&gt; Cities { get; set; }
    }

</details>



huangapple
  • 本文由 发表于 2023年2月14日 08:08:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442323.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定