问题描述
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,"category":"Tiffin"
}
]
}
和
let restaurants:Restaurants = load("Rest.json")