【问题标题】:AFNetworking and JSON parameterAFNetworking 和 JSON 参数
【发布时间】:2015-10-05 04:27:34
【问题描述】:

抱歉,如果这是一个反复出现的问题,但我找不到任何好的答案。

使用 AFNetworking 和 SwiftyJSON。

我需要这样做:

    let locationJArray = JSON(myLocationArray)

    let params = [
         "deviceID" : deviceID
        ,"deviceAPIKey" : deviceAPIKey
        ,"location" : locationJArray
    ]

locationJArray 内容:

[
  {
    "theDirection" : -1,
    "latitude" : -22.90354,
    "longitude" : -43.20959,
    "theAccuracy" : 5,
    "theSpeed" : -1
  }
]

错误:

没有更多上下文的表达类型是模棱两可的

当我尝试将 locationJArray 传递给参数值时。

相反,直接将 myLocationArray 用于参数值是可行的,但 api 完全无法读取数据。

使用 myLocationArray 参数内容:

["deviceID": 68, "location": (
        {
        latitude = "-22.90354";
        longitude = "-43.20959";
        theAccuracy = 5;
        theDirection = "-1";
        theSpeed = "-1";
    }
), "deviceAPIKey": a4465be43ec2b4c3baa50d2ca5ee2be8]

如何将参数值作为 JSON 发送?

【问题讨论】:

    标签: ios json swift2 afnetworking-2 swifty-json


    【解决方案1】:

    对于有相同问题的人:

    let locationJArray = String(JSON(myLocationArray))
    
    let params = [
         "deviceID" : deviceID
        ,"deviceAPIKey" : deviceAPIKey
        ,"location" : locationJArray
    ]
    

    将 JSON 对象转换为字符串解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2013-03-13
      • 2016-03-29
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多