无法解析JSON响应对象Alamofire

时间:2016-12-20 20:15:36

标签: ios json node.js post alamofire

我正在发布帖子请求,并以[Object object]的形式返回JSON响应。我尝试了各种方法来解析这个JSON,但是不能。每当我尝试时,我都会收到错误Could not cast value of type '__NSCFString' (0x10f3dc4a0) to 'NSData'

在后端,我有一个回复res.send的NodeJS服务器。我是否需要将此数据转换为其他内容,或者是否有一种方法可以解析此JSON数据并获取我原本应该获得的Dictionary对象。我使用Swift 3和Alamofire 4.0。

我该如何解决这个问题?

这是我在iOS中的请求代码

Alamofire.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
        debugPrint(response)


        let data_temp = try! JSONSerialization.jsonObject(with: response.result.value! as! Data, options: JSONSerialization.ReadingOptions.mutableContainers)

            print(data_temp)
        } 
    }

0 个答案:

没有答案
相关问题