获取json_encode():类型不受支持,编码为null

时间:2015-01-08 04:21:34

标签: json zend-framework

我正在处理使用json_encode()发送响应的Web服务。 它适用于每个热门Web服务,但我得到 json_encode():类型不受支持,编码为null 仅适用于以下代码。

public function getjobdetailsAction()
    {
        $this->_helper->layout ()->disableLayout ();
        $this->_helper->viewRenderer->setNoRender ( true );

        $handle = fopen ( 'php://input', 'r' );
        $jsonInput = fgets ( $handle );

        $params = Zend_Json::decode ( $jsonInput );


        if($params['user_id'] != "" && $params["job_id"] != "")
        {
            $job_id = $params["job_id"];
            $jobObj=Extended\job::getRowObject( $job_id );
            //check if job obj exist only then send job array to view.
            if($jobObj)
            {
                $job_detail_r = array();
                $job_detail_r['job_id'] = $job_id;
                $job_detail_r['job_created_by'] = $jobObj->getIlookUser()->getId();
                $job_detail_r['job_title'] = $jobObj->getJob_title();

                $job_detail_r['url_fields'] = $jobObj->getUrl_fields();
                $job_detail_r['job_reference'] = $jobObj->getJob_reference();
                $job_detail_r['company_name'] = $jobObj->getCompany()->getName();
                $job_detail_r['responsibilities'] = $jobObj->getResponsibilities();
                $job_detail_r['industry_name'] = $jobObj->getIndustryRef()->getTitle();
                $job_detail_r['skills_expertise'] = $jobObj->getSkills_n_expertise();
                $job_detail_r['country'] = $jobObj->getCountryRef()->getName();

                if( $jobObj->getState() )
                {
                    $job_detail_r['state'] = $jobObj->getState()->getName();
                }
                else
                {
                    $job_detail_r['state'] = "";
                }
                if($jobObj->getCity())
                {
                    $job_detail_r['city'] = $jobObj->getCity()->getName();
                }
                else
                {
                    $job_detail_r['city'] = "";
                }
                //$job_detail_r['job_function'] = $jobObj->getJobFunction()->getDescription();
                $job_detail_r['job_description'] = $jobObj->getJob_description();
                $job_detail_r['company_description'] = $jobObj->getCompany_desc();
                if($jobObj->getSalaryRange())
                {
                    $job_detail_r['salaryRange'] = $jobObj->getSalaryRange()->getCountryRef()->getCurrency_symbol()." ".$jobObj->getSalaryRange()->getMin_salary()." - ".$jobObj->getSalaryRange()->getMax_salary();
                }
                else
                {
                    $job_detail_r['salaryRange'] = "";
                }
                    $job_detail_r['jobType'] = $jobObj->getJobType()->getName();
                //$job_detail_r['experienceLevel'] = $jobObj->getExperieneceLevel()->getMin_experience()." - ".$jobObj->getExperieneceLevel()->getMax_experience()." Years";

                    if($jobObj->getExperieneceLevel())
                    {
                        $job_detail_r['experienceLevel'] = $jobObj->getExperieneceLevel()->getDescription();
                    }
                    else
                    {
                        $job_detail_r['experienceLevel'] = "";
                    }   
                $job_detail_r['job_creator_image'] = Helper_common::getUserProfessionalPhoto( $jobObj->getIlookUser()->getId() );
                $job_detail_r['time_of_post'] =$jobObj->getCreated_at()->format("Y-m-d H:i:s");
                $job_detail_r['job_posted_by'] = $jobObj->getJob_posted_by();
                $job_detail_r['apply_from'] = $jobObj->getApply_from();
                if($jobObj->getJob_image() != "")
                {
                    $job_detail_r['company_image'] = IMAGE_PATH."/jobs/".$jobObj->getJob_image();
                }
                else 
                {
                    $job_detail_r['company_image'] = IMAGE_PATH.'/no_image.png';
                }
                $job_detail_r['is_saved'] = Extended\saved_jobs::isJobSavedByMe($job_id,$params['user_id']);

                $code = 200;
                $msg = "Job details retrieved successfully";
                $result = array("jobdetails"=>$job_detail_r);

            }
            else
            {
                $code = 301;
                $msg = "Error in retrieving details";
            }
        }
        else
        {
            $code = 301;
            $msg = "Missing parameters";
        }
        echo Helper_common::successFailureMsgs($code,$msg,$result);
        exit();






public static function successFailureMsgs( $code, $message, $result = array())
    {

        if($code == 200)
        {
             $result1 = array("Response"=>array("Code"=>$code,"Status"=>"OK","Message"=>$message,"result"=>$result));
        }
        else
        {
             $result1 = array("Response"=>array("Code"=>$code,"Status"=>"Error","Message"=>$message));
        }
        return Zend_Json::encode($result1);

    }

作为回应,我得到了正确的回复,但也出现了上述错误。 请协助。 提前谢谢。

1 个答案:

答案 0 :(得分:4)

对于json_encode(),因此Zend_Json()all types are accepted except resource

因此,您可以调试表以查看资源的位置。 你可以尝试这样的事情:

foreach ($job_detail_r as $k => $v){
    if (is_resource($v))
        echo $k . ' => ressource type = ' . get_resource_type($v);
}