Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
Arrays 当字典的值是字符串数组时使用可解码的解析_Arrays_Json_Swift_Decodable - Fatal编程技术网

Arrays 当字典的值是字符串数组时使用可解码的解析

Arrays 当字典的值是字符串数组时使用可解码的解析,arrays,json,swift,decodable,Arrays,Json,Swift,Decodable,我想解析下面的json文件,但我一直遇到以下错误: 类型不匹配(Swift.Array,Swift.DecodingError.Context(codingPath:[],debugDescription:“应解码数组,但找到了字典。”,underlineerror:nil)) 我看过stackoverflow,但它们似乎没有帮助,因为我没有看到其他json文件返回字符串数组的字典值。有什么想法吗 //JSON file { pugs: [ "http://27.media.tumblr

我想解析下面的json文件,但我一直遇到以下错误:

类型不匹配(Swift.Array,Swift.DecodingError.Context(codingPath:[],debugDescription:“应解码数组,但找到了字典。”,underlineerror:nil))

我看过stackoverflow,但它们似乎没有帮助,因为我没有看到其他json文件返回字符串数组的字典值。有什么想法吗

//JSON file
{
 pugs: [
   "http://27.media.tumblr.com/tumblr_lqfwfyZuyS1qiyqyfo1_500.jpg",
   "http://30.media.tumblr.com/tumblr_liic7bdmRF1qcipjro1_500.jpg",
   "http://29.media.tumblr.com/tumblr_ll3xdp73DQ1qb08qmo1_500.jpg",
   "http://29.media.tumblr.com/tumblr_lht5uy6khS1qed3e3o1_500.jpg",
   "http://26.media.tumblr.com/tumblr_lrqnevtBvM1qb08qmo1_400.jpg",
   "http://26.media.tumblr.com/tumblr_ll90kwmMJw1qzj3syo1_500.jpg",
   "http://26.media.tumblr.com/tumblr_ll7aoxHGfW1qb08qmo1_500.jpg",
   "http://24.media.tumblr.com/tumblr_lk27smb4sR1qzj3syo1_500.jpg",
   "http://26.media.tumblr.com/tumblr_lil8a1m1YM1qzj3syo1_500.jpg",
   "http://27.media.tumblr.com/tumblr_liy1xfY9G71qftdfxo1_500.jpg"
  ]
}

您不需要
Pug
类。将
pugs
更改为
[String]


顺便说一句,除非你有充分的理由使用类,否则使用
struct
而不是
class

BTW,你展示的json是无效的。。。您可能错过了
]
@RobertDresler谢谢您的关注。我没有发布整个阵列,缺少结束括号。。。。甚至到
[URL]
@mir也很乐意帮忙。请不要忘记单击答案左侧的复选标记,表明您的问题已解决。
//Data Model
class PugList: Codable {
    var pugs: [Pug]
    var likes: Int
}

class Pug: Codable {
    var images: [String]
}