2016-05-23 14 views
0

このエラーはJSON result.errorとして表示されます。 、オンラインJSONでそれを確認しvaildator。エラー(エラードメイン= NSCocoaErrorDomainコード= 3840「文字0の値が無効です」UserInfo = {NSDebugDescription =文字0の値が無効}

をこれは、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"}} 

私の場合、何が問題なのか誰も知っていますか?

+0

'responseJSON'の代わりに' .responseString {response in print( "Response String:\(response.result.value)") } 'を実行して、結果がどのように見えるかを確認してください。 – Laffen

+0

'文字の値が無効です'あなたの応答は有効なJSONではありません。 – Moritz

+0

しかし、私はオンラインjsonビューアのサービスの郵便配達の応答をチェックし、それは応答が有効であることを示しています。 – Himanshu

答えて

2

私のWebサービスに問題があります。彼らは私にHTMLではなく "テキスト/ HTML"形式で回答を与えています。私は、デバッガの私の応答を印刷したとき、私は得た:

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

さて、私は自分のWebサービスを更新し、すべてが魅力のように働いています。

+0

どこにこれを含めましたか? – Dazzle

+0

この行はalomafireコードで追加されましたか? –

+0

私のWebサービスの応答。 – Himanshu

2

Webサービスが私の応答を配列で返すという問題があるため、前回と同じエラーが発生しています。その辞書を辞書に変換してその値を抽出しようとしています。

Webサービスの応答を確認してください。

関連する問題