json - 我想在 swift 中为 post 参数创建一个 API JSON 结构
问题描述
我想创建一个嵌套 JSON 以将其用作 Post 方法参数。我尝试了 NSDictionary、Array、[String:Any] 等,但未能获得准确的 JSON 结构。我想要一个 JSON 格式,像这样
{
"Command": [
{
"commandData": {
"name": "name",
"description": "description",
"title": "title",
"actions": [
{
"ERR": [
{
"ERR_LINE": {
"Value": {
"1": 1.0,
"2": 1.0,
"3": 1.0,
"4": 1.0,
"5": 1.0,
"6": 1.0
}
}
}
]
}
]
},
"errID": "id",
"issueID": "id"
}
]
}
解决方案
你可以这样做:
var postData = Dictionary<String,Any>()
postData = [
"Command": [
"commandData": [
"name": "name",
"description": "description",
"title": "title",
"actions": [
"ERR": [
"ERR_LINE": [
"Value": [
"1": 1.0,
"2": 1.0,
"3": 1.0,
"4": 1.0,
"5": 1.0,
"6": 1.0
]
]
]
]
],
"errID": "id",
"issueID": "id"
]
]
希望它有效。
推荐阅读
- windows - 有没有办法在没有窗口询问的情况下用另一个同名文件替换文件?
- google-analytics - Google Analytics(分析)自定义广告系列未报告收入
- javascript - 如何使用 webpack 导入 firebase 并将其服务拆分为多个拆分块?
- regex - 交替与布尔或有何不同?
- angular - 两个垂直和水平选项卡 - 不工作垫选项卡
- ios - 没有从开发 pod 安装并从主项目构建的此类模块“Podname”
- swiftui - SwiftUI:在 Firebase ML Kit 识别的元素周围绘制矩形
- python - Python 3.8.1 - PermissionError: [Errno 13] Permission denied
- c# - 如何在统一上修复此错误:无法将浮点类型隐式转换为 UnityEngine.transform
- python - 似乎无法让 Boto 的 dynamodb.update_item 工作