【发布时间】:2020-10-01 14:44:04
【问题描述】:
这是我想在报告中使用其变量的结构。
struct report : Codable {
var question : String
var AnswersChosen : [String] = [String]()
var userCount : Int
var hintCount : Int
我对用户输入的报告,里面的变量是用户当前的问题,他们选择的选项以及每个问题选择错误答案的次数
var currentReport = [report]()
currentReport.append(report(question:questions[currentQuestion - 1 ],AnswersChosen:answerChosen, userCount:ActionCount, hintCount:hintButtonCount ))
print(currentReport)
这段代码的输出可以这样看:
在我的代码中,我使用 Alamofire 将 JSON 文件发送到 Laravel。我希望能够通过 Alamofire 发送将用户输入记录为 JSON 文件的 currentReport。因此,如何将我的数组转换为 JSON 文件?感谢您的帮助
【问题讨论】:
-
使用
JSONEncoder对其进行编码。请始终以大写字母开头的结构和变量始终以小写字母开头。
标签: json swift struct alamofire