我正在尝试学习一些Swift,现在我被卡住了。我需要一些帮助如何处理JSON以及如何将它放入数组中。我的代码如下。您可以看到我从JSON获得的字典中的外观。我可以请问我的问题一点帮助吗?我将非常感谢任何一个如何解决我的问题,谢谢。
["totalObjects": 3, "nextPage": <null>, "data": <__NSCFArray 0x7fbc4ac2b5a0>(
{
"___class" = Pub;
"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"ratingStaff\",\"address\",\"created\",\"rating\",\"photo\",\"ownerId\",\"phone\",\"smoking\",\"name\",\"___class\",\"openingHours\",\"ratingChicks\",\"ratingPrices\",\"updated\",\"ratingAtmosphere\",\"objectId\"],\"relatedObjects\":{}}";
address = "Ulica 123 Bratislava";
created = 1459407986000;
name = "Deravy Kotlik";
objectId = "DF14F99D-C647-7775-FF63-CE05C3897600";
openingHours = "12-22";
ownerId = "<null>";
phone = 0912345689;
photo = "http://www.fotky.sk/fotka.jpg";
rating = 4;
ratingAtmosphere = 4;
ratingChicks = 5;
ratingPrices = 5;
ratingStaff = 4;
smoking = 0;
updated = "<null>";
},
{
"___class" = Pub;
"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"ratingStaff\",\"address\",\"created\",\"rating\",\"photo\",\"ownerId\",\"phone\",\"smoking\",\"name\",\"___class\",\"openingHours\",\"ratingChicks\",\"ratingPrices\",\"updated\",\"ratingAtmosphere\",\"objectId\"],\"relatedObjects\":{}}";
address = "Pajzel 8, Bratislava";
created = 1458202848000;
name = "Supermanova krcma";
objectId = "4F8B7BCD-515C-0975-FF1F-EC6E2C5A4200";
openingHours = "<null>";
ownerId = "<null>";
phone = "212-555-5555";
photo = "<null>";
rating = "<null>";
ratingAtmosphere = "<null>";
ratingChicks = "<null>";
ratingPrices = "<null>";
ratingStaff = "<null>";
smoking = 1;
updated = 1458202949000;
},
{
"___class" = Pub;
"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"ratingStaff\",\"address\",\"created\",\"rating\",\"photo\",\"ownerId\",\"phone\",\"smoking\",\"name\",\"___class\",\"openingHours\",\"ratingChicks\",\"ratingPrices\",\"updated\",\"ratingAtmosphere\",\"objectId\"],\"relatedObjects\":{}}";
address = "Pajzel 8, Bratislava";
created = 1458202809000;
name = "Supermanova krcma";
objectId = "D9692696-99DD-E2FB-FF86-EA58D91CF500";
openingHours = "<null>";
ownerId = "<null>";
phone = "212-555-5555";
photo = "<null>";
rating = "<null>";
ratingAtmosphere = "<null>";
ratingChicks = "<null>";
ratingPrices = "<null>";
ratingStaff = "<null>";
smoking = 1;
updated = 1458202949000;
}
)
, "offset": 0]
这就是我在用JSON做什么
if let responseData = data
{
do{
let json = try NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.AllowFragments)
if let dict = json as? Dictionary<String, AnyObject>{
print(dict)
}
}catch{
print("Could not serialize")
}
}`enter code here`