应用程序和模拟器上的错误无法启动,Xcode 12.2
Errors on app and simulator not starting, 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 行中设置什么值来修复模拟器?
谢谢,
哈里
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,
"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"
}
]
}
和
let restaurants:Restaurants = load("Rest.json")
我有一个问题。我的页面给我一个错误。它说:
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 行中设置什么值来修复模拟器? 谢谢, 哈里
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,
"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"
}
]
}
和
let restaurants:Restaurants = load("Rest.json")