2013-03-12 112 views
0

我返回一個JSON數組,並試圖得到它控制器,但它顯示沒有結果 這裏是我的模型:此JSON代碼顯示沒有結果

if ((!empty($_FILES["FlMediaImage"])) &&($_FILES["FlMediaImage"]["error"] == 0)) { 
     $mdImgName = $_FILES["FlMediaImage"]["name"]; 
      $ext = substr($mdImgName, strpos($mdImgName, '.') + 1); 
      $mdImgName = 'adsmind_media_' . md5(uniqid(time(), true)) . '.' . $ext; 
      move_uploaded_file($_FILES["FlMediaImage"]["tmp_name"], ROOT . "/images/temp/" . $mdImgName); 
     } 
     $jsonArry = array(
      "image_id" => 0, 
      "image_name" => $result->$mdImgName 
     ); 
     return json_encode(array('result' => $jsonArry)); 

我的控制器:

$imageJSON = json_decode($modObj->saveMediaImage()); 
$imageID = $imageJSON->result->image_id; 
$imageName = $imageJSON->result->image_name; 
+0

嘗試,你可以請打印此$ modObj-> saveMediaImage(),讓我知道結果。 – 2013-03-12 08:24:34

+0

你是否收到任何錯誤? – 2013-03-12 08:25:01

+0

$ modObj-> saveMediaImage()返回json_encode(array('result'=> $ jsonArry)); ?對? – Djomla 2013-03-12 08:25:17

回答

0

你的結果是空兩個瓦爾.. $圖像標識和$ imageName ... 改變一些值,比如

$jsonArry = array("image_id" => '0', "image_name" => 'some_name'); 

你會看到結果。

0

其工作

$arr= json_decode('{"result":{"image_id":0,"image_name":null}}',FALSE); 
echo $arr->result->image_id; 

你可以用它

$imageJSON = json_decode($modObj->saveMediaImage()); 
$imageID = $imageJSON->result->image_id; 
$imageName = (isset($imageJSON->result->image_name) && !empty($imageJSON->result->image_name))?$imageJSON->result->image_name:'';