Swifty JSON 更新到 Xcode 8 后无法使用
Swifty JSON Not Working After Updating to Xcode 8
我的JSON
回复是
{
code = 1;
document = (
{
Address1 = "<null>";
Address2 = "<null>";
City = "<null>";
CompanyID = 1;
CompanyName = Innohabit;
ContactNumber = "<null>";
Designation = "<null>";
DesignationID = 36;
DesignationName = dev;
Email = "uday.mishra@Gmail.com";
FCMRegistrationToken = "";
GCMRegistrationToken = "";
Gender = Male;
ID = 9;
IsActive = 1;
IsFirstLogin = 1;
LastLogin = "2016-09-21 05:45:33";
Name = "Uday Mishra";
Password = "";
ProfilePic = "";
RegisterationDate = "2016-03-04 07:42:42";
UserTwitter = "<null>";
Username = "uday.mishra@Gmail.com";
}
);
message = "Record found";
status = success;
}
并尝试使用 Swifty Json
像这样
转换响应
case .success:
print(response)
let jsonResponse = JSON(response.data)
print("JSON")
let jsonData = jsonResponse["document"]
print(jsonResponse)
print(jsonData[0])
但我没有得到想要的结果,输出是
{
code = 1;
document = (
{
Address1 = "<null>";
Address2 = "<null>";
City = "<null>";
CompanyID = 1;
CompanyName = Innohabit;
ContactNumber = "<null>";
Designation = "<null>";
DesignationID = 36;
DesignationName = dev;
Email = "uday.mishra@Gmail.com";
FCMRegistrationToken = "";
GCMRegistrationToken = "";
Gender = Male;
ID = 9;
IsActive = 1;
IsFirstLogin = 1;
LastLogin = "2016-09-21 05:45:33";
Name = "Uday Mishra";
Password = "";
ProfilePic = "";
RegisterationDate = "2016-03-04 07:42:42";
UserTwitter = "<null>";
Username = "uday.mishra@Gmail.com";
}
);
message = "Record found";
status = success;
}
JSON
unknown
null
如您所见,正在打印响应,但是 print(jsonResponse) 和 print(jsonData[0])
正在打印 Unknown 和 null 任何人都可以帮助我如何将数据从 DataRespose
JSON
正确序列化为 JSON
格式=19=]
请提出任何替代方法,或者如果我做错了请帮助我。
尝试使用下面的代码:
if let jsonResponse: AnyObject = JSON(response.data){
let jsonData = jsonResponse["document"]
print(jsonResponse)
print(jsonData[0])
}
编辑:
我在 this
上阅读了以下声明
The platform of the target Pods (iOS 7.1) is not compatible with SwiftyJSON (2.1.3) which has a minimum requirement of OS X 10.9 - iOS 8.0.
EDIT:
I replaced SwiftyJson.swift with the one in Xcode 6.3 branch and it worked fine now no errors. :-)
所以请尝试按照该步骤操作。
我试过了,效果很好。
Alamofire.request(url, method: .post,parameters: parameters).validate().responseJSON { response in
switch response.result {
case .success(let data):
//print(response)
let jsonResponse = JSON(data)
print("JSON")
let jsonData = jsonResponse["document"][0]
print("Email")
print(jsonData["Email"])
case .failure(let error):
print(error)
}
}
我的JSON
回复是
{
code = 1;
document = (
{
Address1 = "<null>";
Address2 = "<null>";
City = "<null>";
CompanyID = 1;
CompanyName = Innohabit;
ContactNumber = "<null>";
Designation = "<null>";
DesignationID = 36;
DesignationName = dev;
Email = "uday.mishra@Gmail.com";
FCMRegistrationToken = "";
GCMRegistrationToken = "";
Gender = Male;
ID = 9;
IsActive = 1;
IsFirstLogin = 1;
LastLogin = "2016-09-21 05:45:33";
Name = "Uday Mishra";
Password = "";
ProfilePic = "";
RegisterationDate = "2016-03-04 07:42:42";
UserTwitter = "<null>";
Username = "uday.mishra@Gmail.com";
}
);
message = "Record found";
status = success;
}
并尝试使用 Swifty Json
像这样
case .success:
print(response)
let jsonResponse = JSON(response.data)
print("JSON")
let jsonData = jsonResponse["document"]
print(jsonResponse)
print(jsonData[0])
但我没有得到想要的结果,输出是
{
code = 1;
document = (
{
Address1 = "<null>";
Address2 = "<null>";
City = "<null>";
CompanyID = 1;
CompanyName = Innohabit;
ContactNumber = "<null>";
Designation = "<null>";
DesignationID = 36;
DesignationName = dev;
Email = "uday.mishra@Gmail.com";
FCMRegistrationToken = "";
GCMRegistrationToken = "";
Gender = Male;
ID = 9;
IsActive = 1;
IsFirstLogin = 1;
LastLogin = "2016-09-21 05:45:33";
Name = "Uday Mishra";
Password = "";
ProfilePic = "";
RegisterationDate = "2016-03-04 07:42:42";
UserTwitter = "<null>";
Username = "uday.mishra@Gmail.com";
}
);
message = "Record found";
status = success;
}
JSON
unknown
null
如您所见,正在打印响应,但是 print(jsonResponse) 和 print(jsonData[0])
正在打印 Unknown 和 null 任何人都可以帮助我如何将数据从 DataRespose
JSON
正确序列化为 JSON
格式=19=]
请提出任何替代方法,或者如果我做错了请帮助我。
尝试使用下面的代码:
if let jsonResponse: AnyObject = JSON(response.data){
let jsonData = jsonResponse["document"]
print(jsonResponse)
print(jsonData[0])
}
编辑:
我在 this
上阅读了以下声明The platform of the target Pods (iOS 7.1) is not compatible with SwiftyJSON (2.1.3) which has a minimum requirement of OS X 10.9 - iOS 8.0. EDIT: I replaced SwiftyJson.swift with the one in Xcode 6.3 branch and it worked fine now no errors. :-)
所以请尝试按照该步骤操作。
我试过了,效果很好。
Alamofire.request(url, method: .post,parameters: parameters).validate().responseJSON { response in
switch response.result {
case .success(let data):
//print(response)
let jsonResponse = JSON(data)
print("JSON")
let jsonData = jsonResponse["document"][0]
print("Email")
print(jsonData["Email"])
case .failure(let error):
print(error)
}
}