作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想制作一本字典并将这些数据与使用 alamofire 上传的视频文件一起传递。下面是我的 json。
{
"taskid": "2",
"task_type": "N\/A",
"fileName": null,
“videofile”:
"task": [
{
“Cid": 1,
“Start”: "00:00:00",
“End”: "00:00:00"
},
{
“Cid": 2,
“Start”: "00:00:00",
“End”: "00:00:00"
},
{
“Cid": 3,
“Start”: "00:00:00",
“End”: "00:00:00"
},
]
}
下面字典数组的代码应该是什么?如何通过?
multipartFormData.append((self.singleTonFile?.fileUrl)! , withName: "videofile" , fileName: fileNameOnly + ".webm", mimeType: "video/webm")
multipartFormData.append(self.singleTon.userid.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "userid")
multipartFormData.append(self.singleTon.taskid.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "taskid")
multipartFormData.append(self.singleTon. filename.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: "filename")
@里迪。 - 检查我的一个样本的解决方案。这是一种不同的格式。但遵循字典数组作为参数..
for i in 0..<self.singleTon.individualTask.count
{
let dictTask = ["id":self.singleTon.individualTask[i],
"start_time":self.singleTon.individualTaskStartTime[i],
"end_time":self.singleTon.individualTaskEndTime[i],
]
parameters.append(dictTask as [String : AnyObject])
}
]
var dataParameters = Data()
do
{
dataParameters = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions(rawValue: 0))
let objectString = String(data: dataParameters, encoding: .utf8)
print("objectString : ", objectString!)
}
catch
{
}
var alamoDict = [String: Any]()
if let scrn: NSScreen = NSScreen.main() {
let rect: NSRect = scrn.frame
let height = rect.size.height
let width = rect.size.width
self.singleTon.display = "\(height)" + "X" + "\(width)"
}
print("self.singleTon.processor ", self.singleTon.processor)
print("resolution ", self.singleTon.display)
alamoDict = ["task":parameters,
"userid":self.singleTon.userId,
"video_duration":self.singleTon.video_duration,
"fileName":self.singleTon.fileNameForUpload,
"User_type":self.singleTon.User_type,
"OS":self.singleTon.OS,
"processor":self.singleTon.processor,
"task_type":self.singleTon.task_type,
"taskid":self.singleTon.taskIdPassed,
"memory":self.singleTon.memory,
"Freememory":self.singleTon.freememory,
"display":self.singleTon.display,
]
var dataAlamoDict = Data()
//这是为了测试json序列化
*
do
{
dataAlamoDict = try JSONSerialization.data(withJSONObject: alamoDict, options: JSONSerialization.WritingOptions(rawValue: 0))//NSJSONSerialization.dataWithJSONObject(array, options: nil, error: nil)
let objectString = String(data: dataParameters, encoding: .utf8)
print("objectString : ", objectString!)
}
//This is ur alamofire format
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(dataAlamoDict, withName: "TaskInfo")
// …… etc ec*
*
最佳答案
帮助像 riddhi 这样的人
@里迪。 - 检查我的一个样本的解决方案。这是一种不同的格式。但遵循字典数组作为参数..
for i in 0..<self.singleTon.individualTask.count
{
let dictTask = ["id":self.singleTon.individualTask[i],
"start_time":self.singleTon.individualTaskStartTime[i],
"end_time":self.singleTon.individualTaskEndTime[i],
]
parameters.append(dictTask as [String : AnyObject])
}
]
var dataParameters = Data()
do
{
dataParameters = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions(rawValue: 0))
let objectString = String(data: dataParameters, encoding: .utf8)
print("objectString : ", objectString!)
}
catch
{
}
var alamoDict = [String: Any]()
if let scrn: NSScreen = NSScreen.main() {
let rect: NSRect = scrn.frame
let height = rect.size.height
let width = rect.size.width
self.singleTon.display = "\(height)" + "X" + "\(width)"
}
print("self.singleTon.processor ", self.singleTon.processor)
print("resolution ", self.singleTon.display)
alamoDict = ["task":parameters,
"userid":self.singleTon.userId,
"video_duration":self.singleTon.video_duration,
"fileName":self.singleTon.fileNameForUpload,
"User_type":self.singleTon.User_type,
"OS":self.singleTon.OS,
"processor":self.singleTon.processor,
"task_type":self.singleTon.task_type,
"taskid":self.singleTon.taskIdPassed,
"memory":self.singleTon.memory,
"Freememory":self.singleTon.freememory,
"display":self.singleTon.display,
]
var dataAlamoDict = Data()
//这是为了测试json序列化格式
*
do
{
dataAlamoDict = try JSONSerialization.data(withJSONObject: alamoDict, options: JSONSerialization.WritingOptions(rawValue: 0))//NSJSONSerialization.dataWithJSONObject(array, options: nil, error: nil)
let objectString = String(data: dataParameters, encoding: .utf8)
print("objectString : ", objectString!)
}
//This is ur alamofire format
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(dataAlamoDict, withName: "TaskInfo")
// …… etc ec* type ur rest of the code
*
关于ios - 如何在 alamofire 多部分数据中传递字典? iOS swift3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47081381/
我是一名优秀的程序员,十分优秀!