无法读取数据,因为获取谷歌联系人时返回的格式不正确

时间:2017-02-23 14:25:50

标签: ios iphone swift alamofire google-contacts

我正在尝试在我的swift应用程序中检索goole联系人,我收到以下错误。用户成功唱歌。

func getUserContacts(email : String){
        let urlString = "http://www.google.com/m8/feeds/contacts/\(email)/full"
        Alamofire.request(urlString, method: .get)
            .responseJSON { response in

            switch response.result {
            case .success(let JSON):
                print(JSON as! NSDictionary)
            case .failure(let error):
                print(error.localizedDescription)
            }
    }
}

(lldb)po" http://www.google.com/m8/feeds/contacts/(email)/full"     " http://www.google.com/m8/feeds/contacts/emailhere@gmail.com/full"

(lldb) po error.localizedDescription
    "JSON could not be serialized because of error:\nThe data couldn’t be read because it isn’t in the correct format."

(lldb) po response
    ▿ [Request]: GET http://www.google.com/m8/feeds/contacts/emailhere.com/full
    [Response]: <NSHTTPURLResponse: 0x170033da0> { URL: http://www.google.com/m8/feeds/contacts/emailhere.com/full } { status code: 401, headers {
        "Cache-Control" = "private, max-age=0";
        "Content-Encoding" = gzip;
        "Content-Length" = 8761;
        "Content-Type" = "text/html; charset=utf-8";
        Date = "Thu, 23 Feb 2017 14:19:11 GMT";
        Expires = "Thu, 23 Feb 2017 14:19:11 GMT";
        Server = GSE;
        "X-Content-Type-Options" = nosniff;
        "X-Frame-Options" = SAMEORIGIN;
        "X-XSS-Protection" = "1; mode=block";
    } }
    [Data]: 11875 bytes
    [Result]: FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
    [Timeline]: Timeline: { "Request Start Time": 509552351.480, "Initial Response Time": 509552351.663, "Request Completed Time": 509552351.665, "Serialization Completed Time": 509552351.667, "Latency": 0.183 secs, "Request Duration": 0.185 secs, "Serialization Duration": 0.002 secs, "Total Duration": 0.187 secs }
      ▿ request : Optional<URLRequest>
        ▿ some : http://www.google.com/m8/feeds/contacts/emailhere.com/full
          ▿ url : Optional<URL>
            ▿ some : http://www.google.com/m8/feeds/contacts/emailhere.com/full
          - cachePolicy : 0
          - timeoutInterval : 60.0
          - mainDocumentURL : nil
          - networkServiceType : __ObjC.NSURLRequest.NetworkServiceType
          - allowsCellularAccess : true
          ▿ httpMethod : Optional<String>
            - some : "GET"
          ▿ allHTTPHeaderFields : Optional<Dictionary<String, String>>
            - some : 0 elements
          - httpBody : nil
          - httpBodyStream : nil
          - httpShouldHandleCookies : true
          - httpShouldUsePipelining : false
      ▿ response : Optional<NSHTTPURLResponse>
      ▿ data : Optional<Data>
        ▿ some : 11875 bytes
          - count : 11875
          ▿ pointer : 0x0000000104e24000
            - pointerValue : 4376903680
      ▿ result : FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
        ▿ failure : AFError
          ▿ responseSerializationFailed : ResponseSerializationFailureReason
      ▿ timeline : Timeline: { "Request Start Time": 509552351.480, "Initial Response Time": 509552351.663, "Request Completed Time": 509552351.665, "Serialization Completed Time": 509552351.667, "Latency": 0.183 secs, "Request Duration": 0.185 secs, "Serialization Duration": 0.002 secs, "Total Duration": 0.187 secs }
        - requestStartTime : 509552351.480039
        - initialResponseTime : 509552351.66287899
        - requestCompletedTime : 509552351.66534299
        - serializationCompletedTime : 509552351.66746801
        - latency : 0.18283998966217041
        - requestDuration : 0.18530398607254028
        - serializationDuration : 0.0021250247955322266
        - totalDuration : 0.18742901086807251
      ▿ _metrics : Optional<AnyObject>

0 个答案:

没有答案