对于JSONSerialization.jsonObject,Swift Class为[Any]

时间:2018-04-19 18:46:10

标签: ios swift

我正在快速使用Shinobicontrols。我正在尝试将我的类指定为数据源:

getLandGradingData(community: (pickOption?[pickerView.selectedRow(inComponent: 0)])!) { result in

            self.helper?.data = result

        }

func getLandGradingData(community:String, completionHandler:@escaping (_ result:Array<GradingData>) -> Void) {

        var returnedResults = Array<GradingData>()

        WebService().GetLandGradingData(community)
        {
            (result: Array<GradingData>) in

            DispatchQueue.main.async {

                returnedResults = result
                completionHandler(returnedResults)

            }

        }

    }

self.helper?.data期待[Any](var data:[Any]!{get set})

我通过JSONSerialization.jsonObject获取数据

let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! Array<GradingData>

但是当我将它分配给helper.data时它不起作用,但是当我创建这个方法时:

func getTestData() -> [Any]?
    {
        return [GradingData(lot: "lot", andColumns: "andColumns", SLAIssuedFinalGrading: true, SLAIssuedFinalGradingDate: "SLAIssuedFinalGradingDate", CityApprovalIssued: true, CityCommentReceived: false, GradingRepair: "GradingRepair", CurbStopRepair: "CurbStopRepair", SplashPadDownSpout: "SplashPadDownSpout", RYCBOtherRepairs: "RYCBOtherRepairs", Comments: "Comments", columnCamera: "", DepositReceived: false), GradingData(lot: "lot", andColumns: "andColumns2", SLAIssuedFinalGrading: false, SLAIssuedFinalGradingDate: "SLAIssuedFinalGradingDate", CityApprovalIssued: false, CityCommentReceived: false, GradingRepair: "GradingRepair", CurbStopRepair: "CurbStopRepair", SplashPadDownSpout: "SplashPadDownSpout", RYCBOtherRepairs: "RYCBOtherRepairs", Comments: "Comments", columnCamera: "", DepositReceived: false)]
    }

并将其分配给helper.data = getTestData()一切正常,我的问题如何让JSONSerialization.jsonObject返回与getTestData()相同的结构?

0 个答案:

没有答案