如何正确转换NSSingleEntryDictionaryI

时间:2018-06-21 13:42:05

标签: swift

我有这种发布和获取回复的方法

    //Add to Cart Method
    func cart(){

        //getting userId from defaults
        let defaultValues = UserDefaults.standard
        let userId = defaultValues.string(forKey: "userid")

        //creating parameters for the post request
        let parameters: Parameters=[
            "userId":Int(userId!)!
        ]

        //Defined a constant that holds the URL for our web service
        let URL_SELECT_FROM_CART = "http://localhost:8888/restaurant/cart.php?"

        Alamofire.request(URL_SELECT_FROM_CART, method: .post, parameters: parameters).responseJSON {
            response in
            //printing response
            print(response)

            let result = response.result.value

            //converting it as NSDictionary
           let jsonData = result as! [[String:Any]]


        }
    }

这是我的回复输出

SUCCESS: {
    cartItem =     (
                {
            addedTime = "2018-06-20 22:22:52";
            additionalNote = "";
            cartId = 20;
            recipeName = Friedrice;
            recipePrice = "GHS 20";
            recipeQuantity = 2;
            restaurantName = Chucks;
            status = 1;
            totalCost = "2 Plates cost GHS 40";
            userId = 9;
        }
    );
}

运行项目时,我得到

Could not cast value of type '__NSSingleEntryDictionaryI' (0x10472be98) to 'NSArray' (0x10472cf28).

我知道它来自我投射对象的方式,但是如何处理它是我的问题,我是新手。 感谢您的审核和帮助。

0 个答案:

没有答案