【问题标题】:How to send this type of parameter to server call in swift 3.0如何在 swift 3.0 中将此类参数发送到服务器调用
【发布时间】:2017-04-15 07:24:38
【问题描述】:

我需要将以下参数发送到 swift 3.0 中的服务器。如何构建请求参数?

"step_1": [
        {
            "name": "",
            "mobile": "",
            "line_1": "",
            "line_2": "",
            "city": "",
            "state": "",
            "pincode": "",
            "fax": "",
            "gst": "",
            "owner_name": "",
            "dob": "",
            "anniversary": ""
        }
    ]

【问题讨论】:

  • 你尝试了什么???
  • 使用 SwiftyJSON。
  • 这取决于服务器期望什么样的数据。
  • 我建议您使用SwiftHTTP 进行发布请求。这很容易!

标签: ios json swift3


【解决方案1】:

对于上面的json数据,下面是字典代码:

let param = [["name": "abc",
"mobile": "123",
"line_1": "line_1",
"line_2": "line_2",
"city":"xyz",
"state":"abc",
"pincode":"000",
"fax":"123",
"gst":"gst",
"ownwer_name":"ownwer_name",
"dob":"xx-xx-xxxx",
"anniversary":"xx-xx-xxxx"]]

//Print data
print(param[0]["name"] as! String)

【讨论】:

  • 嗨 Sakir Sherasiya...谢谢你给我答案。但它的格式不正确,因为我显示了上面的数据。字典以'{'花括号开头。你能检查一次吗跨度>
  • 你以step_1为父母,其他都是儿童权利
  • 给我服务器的链接
  • 能否举个解析查询数据的例子
  • 使用JSON Validator 确保您的 json 代码正确。
【解决方案2】:

您好,我不确定它是否会起作用,但无论如何,试试这个

let params: ["step_1": [["name": "Some name",
                  "mobile": "12345678",
                  "line_1": "line_1 stuff",
                  "...": "..."]]]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    相关资源
    最近更新 更多