• 技术文章 >后端开发 >php教程

    swift 用Alamofire向后台post Array<Dictionary>类型的数组,后台把它当二维数组解析了?

    2016-06-06 20:15:54原创693
    这个是我post的数据:

    ["content": "", "perform": (
            {
            "perform_id" = 21;
        },
            {
            "perform_id" = 11;
        }
    ), "title": "", "user_id": 10020, "id": 8, "action": join_project, "count": 1]
    

    这个是服务器返回的数据:

    "Array
    array(2) { [0]=> array(1) { [\"perform_id\"]=> string(2) "21" } [1]=> array(1) { ["perform_id"]=> string(2) "11" }}{"result":true,"id":"59"}"

    回复内容:

    这个是我post的数据:

    ["content": "", "perform": (
            {
            "perform_id" = 21;
        },
            {
            "perform_id" = 11;
        }
    ), "title": "", "user_id": 10020, "id": 8, "action": join_project, "count": 1]
    

    这个是服务器返回的数据:

    "Array
    array(2) { [0]=> array(1) { [\"perform_id\"]=> string(2) "21" } [1]=> array(1) { ["perform_id"]=> string(2) "11" }}{"result":true,"id":"59"}"

    哎,是自己SB了,也为了给新手提个醒,给后台post数组或者字典类型的数据时,要转json字符串,可以用系统的NSJSONSerialization来转。代码如下

    let jsonData = try! NSJSONSerialization.dataWithJSONObject(array, options: .PrettyPrinted)
    let jsonString = String(data: jsonData, encoding: NSUTF8StringEncoding)
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:swift php
    上一篇:类似微信微博客户端应用,如何实现让APP通过接口实现登陆一次就不用再次登陆(即登陆一次,就不会过期)? 下一篇:Opcache和APCu有兼容问题吗?
    PHP编程就业班

    相关文章推荐

    • 归纳整理39道PHP面试题(总结分享)• PHP Reflection API详解_PHP教程• php短址转换实现方法,php转换_PHP教程• PHP+Javascript液晶时钟_PHP教程• 用PHP操纵Oracle的LOB类型的数据_PHP教程

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网