使用moya发送swiftyjson数组

问题描述 投票:1回答:1

我正在尝试使用moya发送json对象的swiftyJSON数组,但它会不断产生错误并崩溃。

我的任务如下:

case let .example(token, json):
    return .requestParameters(parameters: ["token": token, "choices": json!.array as Any], encoding: JSONEncoding.default)

其中令牌只是一个字符串,而json是JSON类型。

错误是:

***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'JSON写入(_SwiftValue)中的类型无效]

有什么想法吗?谢谢!

ios swift swifty-json moya
1个回答
0
投票
case let .example(token, json):
  var parameters: [String : Any] = [:]
  parameters["token"] = token
  parameters["choices"] = products.map({
      key, value in
      return [ "product_id": key, "qty": value ]
  })
  return .requestParameters(parameters: parameters, encoding: JSONEncoding.prettyPrinted)
© www.soinside.com 2019 - 2024. All rights reserved.