我已经从PHP和MySQL创建了一个JSON数组。 我已经使用Alamofire从服务器获取响应,但是,我仍然坚持如何使用SwiftyJSON来解析数据,以便我可以将它放入自定义对象数组然后将其加载到tableView中。
我的JSON对象如下所示:
{
person = {
"average_price" = "7430.83";
distance = "3012.984699624479";
"person_id" = 9;
"person_name" = Rerobepicator;
};
}
{
person = {
"average_price" = "2281.35";
distance = "3780.0428863723305";
"person_id" = 7;
"person_name" = Vartanentor;
};
}
{
person = {
"average_price" = "20.00";
distance = "3923.2963365576284";
"person_id" = 16;
"person_name" = bangbang;
};
}
{
person = {
"average_price" = "7430.83";
distance = "3953.934665981184";
"person_id" = 9;
"person_name" = Rerobepicator;
};
}
{
person = {
"average_price" = "747.86";
distance = "4040.1432041597536";
"person_id" = 8;
"person_name" = Happickamex;
};
}
{
person = {
"average_price" = "4967.73";
distance = "4288.827177318351";
"person_id" = 3;
"person_name" = Klibanollover;
};
}
{
person = {
"average_price" = "2281.35";
distance = "4393.581790994688";
"person_id" = 7;
"person_name" = Vartanentor;
};
}
{
person = {
"average_price" = "20.00";
distance = "4792.883669320238";
"person_id" = 16;
"person_name" = bangbang;
};
}
{
person = {
"average_price" = "9857.78";
distance = "6374.9873653967";
"person_id" = 4;
"person_name" = Admunover;
};
}
{
person = {
"average_price" = "747.86";
distance = "6822.324630020093";
"person_id" = 8;
"person_name" = Happickamex;
};
}
{
person = {
"average_price" = "9494.88";
distance = "7177.263972744869";
"person_id" = 10;
"person_name" = Thrukilanicator;
};
}
{
person = {
"average_price" = "8570.38";
distance = "8208.371313460493";
"person_id" = 5;
"person_name" = Undudplazz;
};
}
之所以如此,是因为我这样做是为了拆分每个JSON对象:
if let personobject = JSON as? Array<AnyObject> {
for person in personobject {
println(person)
}
}
}
我现在需要将每个这些加载到我的自定义对象中,如下所示:
class shop {
var shop_name : String?
var shop_type : String?
var averageprice : Float?
init() {
}
}
然后我将它加载到我的Person对象数组中,并使用自定义单元格对象将其加载到我的tableView中。
谢谢:)