0

我有一个连接到dreamfactory 的MySQL 数据库,但我的一些记录是序列化的(PHP)。每当我发送“GET”网络请求时,我编写了一个 PHP 脚本来反序列化它,但它不起作用。我正在使用 AFNetworking 从 Swift xcode 项目中获取我的数据库信息,并希望显示未序列化的信息。

谁能看到我做错了哪一部分?这是我放置 php 脚本和脚本本身的地方:

mysql.table.[tablename}.{id}.get.post_process

$data = $response.meta_value;  

function toJSON($theDATA) {  
$uns = unserialize(unserialize($theDATA));  
$DATA = json_encode($uns);  
return $DATA;  
}  

$new_data = toJSON($data);  
return $new_data;  

这是 php 序列化:

{
"meta_value" = "s:306:\"a:1:{i:274;a:1:{s:9:\"schedules\";a:1:{s:13:\"56f5dc96a042f\";a:5:{s:13:\"minutes_start\";s:3:\"540\";s:11:\"minutes_end\";s:4:\"1020\";s:5:\"weeks\";a:7:{i:1;s:2:\"on\";i:2;s:2:\"on\";i:3;s:2:\"on\";i:4;s:2:\"on\";i:5;s:2:\"on\";i:6;s:2:\"on\";i:0;s:2:\"on\";}s:10:\"date_start\";s:10:\"03/25/2016\";s:8:\"date_end\";s:10:\"06/15/2016\";}}}}\";";
}

这就是我想要得到的 json 正文:

{"274":{"schedules":{"56f5dc96a042f":{"minutes_start":"540","minutes_end":"1020","weeks":{"1":"on","2":"on","3":"on","4":"on","5":"on","6":"on","0":"on"},"date_start":"03\/25\/2016","date_end":"06\/15\/2016"}}}}
4

0 回答 0