1

i want to send json body to my middleware. at first, it works well (note that the "tema" & "emailGroup" wasn't an array). but after some changes on my backend, i have to send this type of 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
}]

here's my code

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]]

where tema is

var tema = [String : Int]()

i got an error that says

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

and after i change "as" to "as!", it says

Excpected ";" separator

where the semicolon should put near "SerializationKeys.tema : [tema]". Please kindly help me. Thanks

EDIT enter image description here

1 Answer 1

1

I think you mistakenly added ] near

, SerializationKeys.postLink : channel.postLink],

You may want this

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]
               ]]

Note: I heighly recommend using Codable with struct models for your case

Sign up to request clarification or add additional context in comments.

4 Comments

hello, thanks for spotting my mistake. anyway, i still got an error "Excpected ";" separator". can you please provide me the code?
Can you screenshoot the error when appear and attach it temporarily in question then remove it
look at my updated question. the other word says "Variable usde within its own initial value"
Before as there is 3 ]]] not 2 ]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.