-1

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

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 存储库

4

1 回答 1

1

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")
于 2020-12-23T20:43:10.037 回答