Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift JSON write DemographicsPojo中的NSInvalidArgumentException无效类型_Swift_Alamofire - Fatal编程技术网

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
块捕获可能的错误。还设置异常断点以获取有关异常的详细信息。