gpt4 book ai didi

json - 发送数组 json 主体,其中包含数组(Alamofire、Swift、iOS)

转载 作者:行者123 更新时间:2023-11-28 05:52:20 26 4
gpt4 key购买 nike

我想将 json 正文发送到我的中间件。起初,它运行良好(请注意,“tema”和“emailGroup”不是一个数组)。但是在我的后端进行了一些更改之后,我必须发送这种类型的 json

[{
"ID": "",
"Name": "Artikel BU CE - Visit HoB Topic",
"ChannelType": 0,
"PublishDate": "2018-09-21T01:00:00Z",
"Headline": null,
"Content": null,
"EmailSubject": null,
"EmailUrl": null,
"Mention": null,
"PostLink": null,
"ChannelActivityMobileId": null,
"HashTag": null,
"Tema": [
{
"Value": 6
}
],
"EmailGroup": [
{
"ID": "2c53ea1f-6ebe-e811-a977-000d3aa00fc2",
"Name": "TV Broadcast",
"List_EmailListModels": null
}
],
"ApprovalStatus": 0,
"ApprovalNote": null,
"EmployeeId": null,
"EmployeeLevel": 0
}]

这是我的代码

let parameters = [["ID" : "", SerializationKeys.channelMobileId : channel.mobileId, SerializationKeys.name : activity.activityName, "ApprovalStatus" : channel.channelStatus, SerializationKeys.channelType : channel.channelType, SerializationKeys.publish_date : channel.publishDate, SerializationKeys.content : channel.content,  SerializationKeys.emailSubject : channel.emailSubject, SerializationKeys.emailURL : channel.emailURL, SerializationKeys.hashtag : channel.hastag, SerializationKeys.mention : channel.mention, SerializationKeys.note : channel.note, SerializationKeys.postLink : channel.postLink, SerializationKeys.tema : [tema]] as [[String : Any]]

主题在哪里

var tema = [String : Int]()

我收到一条错误消息

[Any] is not convertible to '[[String : Any]]'; did you mean to use as! to force downcast?

在我将“as”更改为“as!”之后,它说

Excpected ";" separator

分号应该放在“SerializationKeys.tema : [tema]”附近。请帮助我。谢谢

编辑 enter image description here

最佳答案

我想你错误地添加了 ] near

, SerializationKeys.postLink : channel.postLink],

你可能想要这个

let parameters:[[String:Any]] = [["ID" : "",
SerializationKeys.channelMobileId : channel.mobileId,
SerializationKeys.name : activity.activityName,
"ApprovalStatus" : channel.channelStatus,
SerializationKeys.channelType : channel.channelType,
SerializationKeys.publish_date : channel.publishDate,
SerializationKeys.content : channel.content,
SerializationKeys.emailSubject : channel.emailSubject,
SerializationKeys.emailURL : channel.emailURL,
SerializationKeys.hashtag : channel.hastag,
SerializationKeys.mention : channel.mention,
SerializationKeys.note : channel.note,
SerializationKeys.postLink : channel.postLink,
SerializationKeys.tema : [tema]
]]

注意:我强烈建议您将 Codablestruct 模型一起用于您的案例

关于json - 发送数组 json 主体,其中包含数组(Alamofire、Swift、iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52488021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com