使用Alamofire

时间:2016-11-12 00:08:16

标签: ios swift alamofire

我试图运行以序列化JSON响应,但我在“let json = ...”行上收到错误。错误是“对成员'的模糊引用'jsonObject(with:options :)'”。如果有人知道如何解决这个问题,我会知道如何解决这个问题

    Alamofire.request("https://httpbin.org/get").responseJSON { response in

        if let JSON = response.result.value {

            do {
                let json = try JSONSerialization.jsonObject(with: response.result.value!, options: .allowFragments)

            } catch {
                print ()
            }

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

1 个答案:

答案 0 :(得分:1)

因为function menuItemListener( link ) { var side = link.getAttribute("data-action"); if (side == 'Mark as A' || side == 'Mark as B') { highlighter(side); $.ajax({ method: "POST", url: "http://localhost:3000/", dataType: "json", data: JSON.stringify({"rangyobject" : rangy.saveSelection()}), contentType: "application/json; charset=utf-8", success: function(result) { console.log('yei'); } }); } toggleMenuOff(); } function loadHighlights () { window.addEventListener("load", function load(event){ $.ajax({ method: "GET", url: "http://localhost:3000/ranges", dataType: "json", contentType: "application/json; charset=utf-8", success: function(result) { console.log('loadHighlights results: ', result[0].rangyObject); rangy.restoreSelection(result[0].rangyObject); } }); 是字典response.result.value的类型,而不是预期的__NSDictionaryI数据。您可以轻松地从jsonObject检索值,无需转换为json,例如:JSON