私は2つの正確にjsonオブジェクトを持っていますが、1つは関数から作成され、もう1つはハードコードされています。 。?奇妙でエラーinvalid top-level type
、どれ先端TKSswift 3、JSON、書き込み時に無効なトップレベルタイプ
let myData = self.dailyMileage?.toDictionary()
let directData = ["orgId" : self.orgId, "driverId" : self.driverId, "date" : Utils.getTodaysDate() ] as [String : Any]
//this won't work unless I substitute myData with directData
let jsonData = try JSONSerialization.data(withJSONObject: myData, options: .prettyPrinted)
//this is the function that produces myData, and nothing is nil
public func toDictionary() -> [String : Any] {
let dict = [ "orgId" : orgId , "driverId": driverId, "date" : date] as [String : Any]
return dict
}
'myData'はオプションなので問題はありますか? – rmaddy
myDataインスタンスを調べ、実際に正しいことを確認するために、jsonData行にブレークポイントを設定しましたか? – TheValyreanGroup
@TheValyreanGroupはい、私はそうでした、それは彼らが全く同じだと言った理由です –