Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS XCode中为JSON定义结构?_Ios_Json_Xcode_Struct_Declare - Fatal编程技术网

如何在iOS XCode中为JSON定义结构?

如何在iOS XCode中为JSON定义结构?,ios,json,xcode,struct,declare,Ios,Json,Xcode,Struct,Declare,作为iOS的新手,XCode我正在尝试创建一个表示JSON数据的结构。然而,不管我如何定义“段”(由一个int和一个字符串数组组成),XCode只会出错,而当我尝试遵循建议的修复方法时,它只会生成其他错误 有人知道如何为JSON定义一个命名的结构,例如不使用“ANY”,因为所有的名称-值对和数据类型都是已知的吗 示例XCODE(下面显示了一种变体,尽管已经尝试了几十种并产生了错误): 这与顶层相同:您必须为较低层创建一个结构 struct Information: Decodable {

作为iOS的新手,XCode我正在尝试创建一个表示JSON数据的结构。然而,不管我如何定义“段”(由一个int和一个字符串数组组成),XCode只会出错,而当我尝试遵循建议的修复方法时,它只会生成其他错误

有人知道如何为JSON定义一个命名的结构,例如不使用“ANY”,因为所有的名称-值对和数据类型都是已知的吗

示例XCODE(下面显示了一种变体,尽管已经尝试了几十种并产生了错误):


这与顶层相同:您必须为较低层创建一个结构

struct Information: Decodable {
    let entry: [Entry]
}
struct Entry: Decodable {
    let section: Int
    let segments: [Segment]
}
struct Segment: Decodable {
    let id: Int 
    let values: [String]
}

瓦迪安,这个建议很有效!我不知道它必须像这样分解结构的内部部分。我要去了解更多关于这个新XCode的信息(至少对我来说是新的),再次感谢!
{
  "entry": [
    {
      "section": 1,
      "segments": [
        {
          "id": 1,
          "values": ["1", "2", "3"]
        },
        {
          "id": 2,
          "values": [ "4", "5", "6" ]
        }
      ]
    },
    {
      "section": 2,
      "segments": [
        {
          "id": 1,
          "values": ["7", "8", "9"]
        },
        {
          "id": 2,
          "values": [ "a", "b", "c" ]
        }
      ]
    }
  ]
}
struct Information: Decodable {
    let entry: [Entry]
}
struct Entry: Decodable {
    let section: Int
    let segments: [Segment]
}
struct Segment: Decodable {
    let id: Int 
    let values: [String]
}