【问题标题】:Swift RestKit won't post JSON in bodySwift RestKit 不会在正文中发布 JSON
【发布时间】:2016-06-17 03:26:42
【问题描述】:

我需要发布一个帖子来接收返回的 JSON 以填充我的 CoreData。到目前为止,我只做 GET。

当我查看查尔斯的电话时,无论是什么组合,身体里什么都没有。

let storedProcedureParams =
    [
        "params": [
            [
            "name": "p_latitude",
            "param_type": "IN",
            "value": latitude
            ],
            [
            "name": "p_longitude",
            "param_type": "IN",
            "value": longitude
            ],
            [
            "name": "p_distance",
            "param_type": "IN",
            "value": distance
            ],
            [
            "name": "p_user",
            "param_type": "IN",
            "value" : user
            ],
            [
            "name": "p_appKey",
            "param_type": "IN",
            "value" : appDelegate.api_key
            ]
        ],
        "schema": [
            "id": "integer",
            "complete": "boolean"
        ],
        "wrapper": "record"
    ]

    let mapping = RKObjectMapping.requestMapping()
    mapping.addAttributeMappingsFromDictionary(storedProcedureParams)

    let requestDescriptor = RKRequestDescriptor(mapping:mapping,objectClass:Store.self, rootKeyPath:nil, method:RKRequestMethod.POST)


    objectManager.addRequestDescriptor(requestDescriptor)
    objectManager.addResponseDescriptor(responseDescriptor )
    objectManager.requestSerializationMIMEType = RKMIMETypeJSON
    objectManager.postObject(storedProcedureParams, path: "_proc/StoresByDistance", parameters: nil,
                             success:{ operation, mappingResult in
                                NSLog("success")


        },
                             failure:{ operation, error in
                                NSLog("Error loading list': \(error!.localizedDescription)")
                                //return nil
        }
    );

有什么明显的吗?

【问题讨论】:

    标签: json swift core-data restkit-0.20


    【解决方案1】:

    显然,我必须将 requestDescriptor 设置为 nil,然后使用在正文中发送它的参数。

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 2017-09-07
      相关资源
      最近更新 更多