如何以正确的格式获取json对象

时间:2015-07-23 12:16:47

标签: php json

这是我的PHP网络服务代码:

if($job_id!='')
{
$strj="select * from pre_jobs where job_id=$job_id";
$resj=selectone($strj);
$ex=explode(",",$resj['type_of_service']);
 $r4=array();
if($ex[0]!=''){
foreach($ex as $exx)
{

$strj1="select * from  company_services where id=$exx";
$resj1=selectone($strj1);

//$resj['job_service']=$resj1;
array_push($resj,$resj1);
}
//print_r($resj1);die();
}
array_push($r4,$resj);

}

使用该代码,我从表中获取数据并将其显示在Web服务URL上 数据来自

{"result":true,"av":{"id":"21","title":"many stairs","company_id":"0","time_from":"2015-06-10 08:33:00","time_to":"2015-06-12 10:33:00","longitude":"11.58337","latitude":"48.14601","street":"k\u00f6niginstr.11","city":"M\u00fcnchen","state":"Germany","zip":"","no":"","status":"2","employee_id":"","job_id":"6","created":"2015-06-02 05:47:35","modified":"2015-06-02 05:47:35"},"emp":"","comp":null,"job":[{"job_id":"6","job_name":"many stairs","created_by":"5","job_from":"2015-06-10 08:33:00","job_to":"2015-06-12 10:33:00","time_acceptance":"10","job_exp":"2015-06-10 08:43:00","type_of_service":"12,5,10","no_of_person_need":"15","job_description":"","address_street":"k\u00f6niginstr.11","address_city":"M\u00fcnchen","address_state":"Germany","address_zip":"250001","no":"","longitude":"11.58337","latitude":"48.14601","public":"1","job_status":"4","0":{"id":"12","service":"Carry furniture safely from and to trucks"},"1":{"id":"5","service":"Assembly\/disassembly of lamps with tools"},"2":{"id":"10","service":"Truck driver with license"}}]}

但我想要那种格式

{"result":true,"av":{"id":"21","title":"many stairs","company_id":"0","time_from":"2015-06-10 08:33:00","time_to":"2015-06-12 10:33:00","longitude":"11.58337","latitude":"48.14601","street":"k\u00f6niginstr.11","city":"M\u00fcnchen","state":"Germany","zip":"","no":"","status":"2","employee_id":"","job_id":"6","created":"2015-06-02 05:47:35","modified":"2015-06-02 05:47:35"},"emp":"","comp":null,"job":[{"job_id":"6","job_name":"many stairs","created_by":"5","job_from":"2015-06-10 08:33:00","job_to":"2015-06-12 10:33:00","time_acceptance":"10","job_exp":"2015-06-10 08:43:00","type_of_service":"12,5,10","no_of_person_need":"15","job_description":"","address_street":"k\u00f6niginstr.11","address_city":"M\u00fcnchen","address_state":"Germany","address_zip":"250001","no":"","longitude":"11.58337","latitude":"48.14601","public":"1","job_status":"4",""job_serv":":[{"id":"12","service":"Carry furniture safely from and to trucks"},"{"id":"5","service":"Assembly\/disassembly of lamps with tools"},{"id":"10","service":"Truck driver with license"}]}]}

如何实现这种格式?

0 个答案:

没有答案