错误(错误域= NSCocoaErrorDomain代码= 3840“字符0周围的值无效。”UserInfo = {NSDebugDescription =字符0周围的值无效}

问题描述 投票:0回答:3

我收到此错误为JSON result.error。虽然我的JSON是有效的,但请在线查看JSON vaildator。

这是我的JSON请求代码。

Alamofire.request(.POST, url, parameters: parameters, encoding:.JSON)
                .responseJSON { (request, response, result) in
                    hud.hide(true)
                    // Set flag to disale poor internet connection alert
                    weakInternet = false
                    print(result.error)
                    if (result.value != nil) {
                        print("API Response: \(result.value!)")
                        // Pass the response JSON to the completion block
                        completion(json: result.value!)
                    } else {
                        // Response JSON is NULL
                    }
            }

当我使用特定的请求参数点击相同的服务时,我得到了这个响应。

{"error":"success","post_data":{"first_name":"hd","last_name":"df","email":"[email protected]","password":"himanshu","confirm_password":"himanshu","companies":["Big Rattle Technologies_Fg_yes"],"institutes":[""]},"msg":"success","data":{"_id":"5742ae1564b35e37369f0838","first_name":"hd","last_name":"df","email":"[email protected]","profile_pic":"","loc":[0,0],"locs":{"type":"Point","coordinates":[0,0]},"institutes":[],"companies":[{"comapny_id":"555b2d0a678e79ed510041ce","group_id":"556c2434678e79a1820041dd","name":"Big Rattle Technologies","designation":"Fg","is_current":"yes"}],"device_token":"","user_group":"site_user","is_verified":0,"is_disclose":1,"is_discover":1,"wallNotification":1,"messageNotification":1,"matchNotification":1,"verificationSent":0,"status":1,"mobile":"","linkedin_id":"","facebook_id":"","os":"","qblox_id":12957726,"updated_at":"2016-05-23 07:15:33","created_at":"2016-05-23 07:15:33","current_company":"Big Rattle Technologies"}}

有谁知道我的问题是什么?

ios json swift alamofire
3个回答
4
投票

我的网络服务存在问题。他们以“text / HTML”格式而不是HTML格式给我回复。当我在调试器上打印我的响应时,我得到了:

"Content-Type" = "text/html; charset=UTF-8";

现在,我更新了我的网络服务,一切都像魅力一样。


2
投票

我上次得到相同的错误,因为会有问题是Web服务返回我在数组中的响应,我试图将其转换为字典并提取其值。

检查您的Web服务响应。


0
投票

Swift 5,Swift 4

var headers = HTTPHeaders()
    headers = [
        "Content-Type" :"text/html; charset=UTF-8",
        //"Content-Type": "application/json",
        //"Content-Type": "application/x-www-form-urlencoded",
        //"Accept": "application/json",
        "Accept": "multipart/form-data"
    ]
© www.soinside.com 2019 - 2024. All rights reserved.