Swift JSON write DemographicsPojo中的NSInvalidArgumentException无效类型
当我尝试使用Swift JSON write DemographicsPojo中的NSInvalidArgumentException无效类型,swift,alamofire,Swift,Alamofire,当我尝试使用swift 3code上的Alamofire运行以下JSONSerialization时,我得到一个NSInvalidArgumentException 试试看!JSONSerialization.data(带jsonObject:postData,选项:JSONSerialization.WritingOptions.prettyPrinted) 调试时,postData返回以下值 key __NSCFString * "demographicsPojo" 0x00006080
swift 3
code上的Alamofire
运行以下JSONSerialization
时,我得到一个NSInvalidArgumentException
试试看!JSONSerialization.data(带jsonObject:postData,选项:JSONSerialization.WritingOptions.prettyPrinted)
调试时,postData
返回以下值
key __NSCFString * "demographicsPojo" 0x000060800005e8a0
value _TtC7MyApp16DemographicsPojo * 0x6080001c5cd0 0x00006080001c5cd0
[0] _TtC7MyApp16DemographicsPojo
createdTimeMilliSecs Int64? 1487253369999
dateOfBirthMilliSecs Int64? 1487253369999
demographicsRoleType Int? 3
gender Int? 0
isDemographicsActive Int? 3
isRecordActive Int? 0
isTermsAndConditionsAccepted Int? 3
licenseExpiryDate Int64? 1487253369999
mobilePhone String? "9876543210" some
termsAndConditionsAcceptedTime Int64? 1487253369999
termsAndConditionsText String? "" some
updatedTimeMilliSecs Int64? 1487253369999
我不熟悉
Swift 3
。我使用基于Android的JSON文件将DemographicsPojo
反向工程到swift。我想知道我是否需要避免在Pojo中完全使用选项
?这就是问题所在吗?Swift不会将任意对象序列化为JSON字符串。您可以通过调用JSONSerialization.isValidJSONObject
来检查这一点
您需要先将对象转换为字典。或者使用第三方JSON序列化程序库,如Swift不会将任意对象序列化为JSON字符串。您可以通过调用
JSONSerialization.isValidJSONObject
来检查这一点
您需要先将对象转换为字典。或者使用第三方JSON序列化程序库,比如不要使用
试试代码>不小心。使用do catch
块捕获可能的错误。同时设置异常断点以获取有关异常的详细信息。不要使用try代码>不小心。使用do catch
块捕获可能的错误。还设置异常断点以获取有关异常的详细信息。