ios - Alamofire json返回 "="而不是 ":"

标签 ios json swift alamofire

你好,我刚刚实现了 Alamofire,它运行良好,但结果不是 json

    let UrlString = urlString
    let url = NSURL(string: UrlString)!
    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = hTTPMethod
    request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
    request.setValue("application/json", forHTTPHeaderField: "Accept")
    let HttpBodyString = httpBody
    let data = HttpBodyString.dataUsingEncoding(NSUTF8StringEncoding)

    request.HTTPBody = data

    Alamofire.request(request)
       // .validate()
        .responseJSON { response in  
if let JSON = response.result.value {

        print("JSON: \(JSON)")
}

它给了我

JSON: (
        {
        "Area_ID" = 2;
        "City_ID" = 5;
        "House_Building_No" = 2;
        "House_Floor" = 2;
        "House_QRCode" = 1;
        "Region_ID" = 6;
        "Street_ID" = 2;
    }
)

这不是我想要的 json:not = 也给我;不,

最佳答案

Alamofire 的 responseJSON 方法中的 response.result.value 变量是一个 NSDictionary。您看到的打印输出是打印 NSDictionaries 的默认方式。

如果您想要一个包含 JSON 的字符串,以标准格式表示(即在键和值之间使用“:”),请尝试使用 responseString 方法。

或者,如果您想要一个 JSON 对象,您可以使用 SwiftyJSON并执行以下操作:

Alamofire.request(request).responseJSON {
    response in  
    if let jsonDictionary = response.result.value {
        let json = JSON(jsonDictionary)
        print(json)
    }
}

关于ios - Alamofire json返回 "="而不是 ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36606145/

相关文章:

iOS 位置服务 - 应用程序在允许之前检查位置

json - 还有其他方法可以针对JSON中的多个嵌套字段优化此Elasticsearch查询

ios - 如何防止 UITableViewCell 在部分刷新时丢失其选择状态?

ios - 什么时候 View 会根据它们的父 View 自动转换?

ios - swift 上的 Alamofire 返回状态代码问题

ios - TouchID with KeyChain - 输入密码屏幕出现格式错误 (Swift)

swift - 使用 double 对 UITableView 进行排序

ruby-on-rails - 如何将参数从 Controller 传递到我的序列化程序?

python - 如何读取json和python中的child?

Swift AVPlayer 到耳机