3

I am working on web services where am using json_encode() to send my response . It is working fine for every ther web service but I am getting json_encode(): type is unsupported, encoded as null for the following code only.

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);

    }

In response I am getting correct response but the above error as well . Please assist. Thanks in advance.

2
  • On page from where I am fetching all this information there we have applied ckeditor. Commented Jan 8, 2015 at 4:39
  • Did you try json_encode() Commented Jan 8, 2015 at 5:09

1 Answer 1

5

For json_encode(), and therefore Zend_Json(), all types are accepted except resource.

So you have debbuger your table to see where the resource is located. You can try something like this:

foreach ($job_detail_r as $k => $v){
    if (is_resource($v))
        echo $k . ' => ressource type = ' . get_resource_type($v);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you doydoy44. I have used get_stream_contents to change resource into string and now its working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.