-1

我在使用 swift 时遇到问题,因为我需要这样发送Json

 {
   "package": {
     "description": "Pink iPad",
     "contentValue": 120.01,
     "weight": 1.01,
     "length": 30.01,
     "height": 15.01,
     "width": 20.01
   },
   "origin_zip_code": "44100",
   "destination_zip_code": "44510"
 }
 

这是我的尝试:

   let package : [String: Any?] = [
    "description": "Pink iPad",
        "contentValue": 120.0,
        "weight": 1.01,
        "length": 30.01,
        "height": 15.01,
        "width": 20.01
    ]

    
     parameters = [
        "package": package,
        "origin_zip_code": "44100",
        "destination_zip_code": "44510"
    ]

当我收到 Alamofire 的回复时,我收到以下消息:

failure(Alamofire.AFError.responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})))

它出什么问题了?非常感谢您的阅读

4

1 回答 1

0

你可以使用Parameters Object

 let package: Parameters = [
            "description" : "Pink iPad",
                "contentValue": 120.0,
                "weight": 1.01,
                "length": 30.01,
                "height": 15.01,
                "width": 20.01
        ]

let parameters : Parameters = [
            "origin_zip_code": "44100",
            "destination_zip_code": "44510",
            "package": package
        ]
于 2021-01-07T19:26:05.570 回答