0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ObjectMapper failed to serialize responseが出たらJSONを疑え

Posted at

##はじめに
APIでJSONを取得してくる時に、静かにエラーになっていた。
ニュースアプリを作っているのですが、記事の筆者の情報が取れていなかった。

##環境
pod 'AlamofireObjectMapper', '~> 5.2'
pod 'ObjectMapper', '~> 3.4'
Swift4.2
Xcode11
target🎯 iOS:12.1

##エラーと対処法

NetworkUtils.swift
let requestReference = Alamofire.request(url, method: .get).responseArray(keyPath: keyPath) { 
  (response: DataResponse<[T]>) -> Void in
      if let result = response.result.value {
            observer.onNext(
            observer.onCompleted()
       } else if let error = response.result.error {
            (こっちに入っていた)
       }

errorを見てみると、

ObjectMapper failed to serialize response
とある。

調べてみるとJSONの内容が怪しいとのこと。

JSONが正しいか判断してくれるサイト↓
https://jsonlint.com/

ここで、無駄な改行を消したらソースは変更せずに解決しました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?