【Swift4】error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: “The given data was not valid JSON.”,・・・

Swift4の入門書にて通信するアプリを作るサンプルをダウロードしapiのurlを設定してビルドしたら下記のようなエラーが出た。

error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}))

サンプルのエンドポイントはjsonをjsonを取得するものだったのに対し自分が設定したエンドポイントはxmlを取得するものだったためエラーになったよう。
エンドポイントをjsonのものに変更したらうまくいきました。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする