应用程序和模拟器上的错误未启动,Xcode 12.2

问题描述

我有一个问题。我的页面给了我一个错误。它说:

Fatal error: Couldn't parse Rest.json as Array<Restaurant>:
dataCorrupted(Swift.DecodingError.Context(codingPath: [],debugDescription: "The given data was not valid JSON.",underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}))): file SaimirrasKitchen/ModelData.swift,line 30

在 RestaurantRow.swift 文件的第 21 行中修复模拟器的值是什么? 谢谢, 哈里

Github Respoitory

解决方法

json 字符串无效,对于您的示例,它应该是:

{"restaurants": [
    {
        "id":1001,"name":"Chapathi","imageName":"Chapathi","description":"Chapathi is a type of roti bread that is served all around the world.It is made of of wheat flour,oil,and water. Rolled and placed on a tawa.","category":"Tiffin"
    },{
        "id":1002,"category":"Tiffin"
    }
  ]
}

let restaurants:Restaurants = load("Rest.json")