Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我想将字符串转换为字典swift 4_Ios_Iphone_Ipad_Alamofire_Swift4 - Fatal编程技术网

Ios 我想将字符串转换为字典swift 4

Ios 我想将字符串转换为字典swift 4,ios,iphone,ipad,alamofire,swift4,Ios,Iphone,Ipad,Alamofire,Swift4,如何在swift中将字符串转换为字典 我的代码 Alamofire.request(apiMethod).responseJSON { response in let statCode = response.response?.statusCode print("URLRequest: \(String(describing: response.request!))") print("RequestSuccess: \(String(describ

如何在swift中将
字符串
转换为
字典

我的代码

Alamofire.request(apiMethod).responseJSON { response in
        let statCode = response.response?.statusCode
        print("URLRequest: \(String(describing: response.request!))")
        print("RequestSuccess: \(String(describing: response.result.isSuccess))")
        print("statusCode: \(statCode!)")
        print("Response: \(String(describing: response.response!))")
        print("Result: \(response.result)")

        if let json = response.result.value {
            print("JSON: \(json)")
        }

        if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {

            print(utf8Text) 


        }

    }
=======================

out code是我的
字符串
我需要更改为
字典

{“结果”:[{“类别”:2,“名称”:“测试”,“子类别”:[],“id”:2},{“类别类型”:1,“名称”:“测试” “子类别”:[{“categoryId”:1,“名称”:“categoryName”:“类别名称”:“categoryName”:” “id”:1,{“categoryId”:1,“name”:“categoryName”:“categoryName”:“categoryName”:“categoryName”:“categoryName”:“categoryName”:“categoryName”: “id”:2}],“id”:1}],“targetUrl”:null,“success”:true,“error”:null,“unAuthorizedRequest”:false,“u abp”:true}”


其他打印输出是什么?在使用Alamofire时,由于使用了
.responseJSON{}
,您应该已经将一个序列化的JSON放入字典中。
如果让JSON=response.result.value{print(“JSON:\(JSON)”)}
-在这个块中查找json。
let dictionary = try? JSONSerialization.jsonObject(with: string, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String:Any]