2017-05-23 11 views
0

多次元配列を持っているので、配列から 'img'データを取得したい。配列から画像データを取得する方法

以下は私の結果の配列である、

"{'0':{'id':'area-design'},'1':{'id':'images-1','width':'500px','height':'500px','top':'0px','left':'0px','zIndex':'auto','img':'http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-fbfe5ba2144332567936169114610928496.png'}}""{'0':{'id':'area-design'},'1':{'id':'images-1','width':'500px','height':'500px','top':'0px','left':'0px','zIndex':'auto','img':'http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-fbfe5ba2144332567936169114610928496.png'}}""{'0':{'id':'area-design'},'1':{'id':'images-1','width':'500px','height':'500px','top':'0px','left':'0px','zIndex':'auto','img':'http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-56a3107c144332567919932061810464914.png'}}""{'0':{'id':'area-design'},'1':{'id':'images-1','width':'500px','height':'500px','top':'0px','left':'0px','zIndex':'auto','img':'http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-69b4fa3b144332567968295645910544813.png'}}" 

以下のコードは、

$file = dirname(DIR_SYSTEM) . '/tshirtecommerce/data/products.json'; 

if (file_exists($file)) 
{  
    $string = file_get_contents($file); 
    if ($string != false) 
    { 
    $e_products = json_decode($string); 
    if (isset($e_products->products) && count($e_products->products) > 0) 
    { 
     foreach($e_products->products as $values) 
     { 

     foreach ($values->design->back as $ck => $ch){ 
      echo json_encode($ch); 
     } 
     } 
    } 
} 
} 
+1

をあなたの 'JSON'が有効ではありません。 –

+0

jsonの無効な[http://jsonviewer.stack.hu/]を確認してください –

+0

私はjsonのキーと値が二重引用符で囲まれていると思います – JYoThI

答えて

0

あなたのJSONは無効です!私は有効に変換:

[ 
    { 
     "0":{ 
     "id":"area-design" 
     }, 
     "1":{ 
     "id":"images-1", 
     "width":"500px", 
     "height":"500px", 
     "top":"0px", 
     "left":"0px", 
     "zIndex":"auto", 
     "img":"http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-fbfe5ba2144332567936169114610928496.png" 
     } 
    }, 
    { 
     "0":{ 
     "id":"area-design" 
     }, 
     "1":{ 
     "id":"images-1", 
     "width":"500px", 
     "height":"500px", 
     "top":"0px", 
     "left":"0px", 
     "zIndex":"auto", 
     "img":"http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-fbfe5ba2144332567936169114610928496.png" 
     } 
    }, 
    { 
     "0":{ 
     "id":"area-design" 
     }, 
     "1":{ 
     "id":"images-1", 
     "width":"500px", 
     "height":"500px", 
     "top":"0px", 
     "left":"0px", 
     "zIndex":"auto", 
     "img":"http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-56a3107c144332567919932061810464914.png" 
     } 
    }, 
    { 
     "0":{ 
     "id":"area-design" 
     }, 
     "1":{ 
     "id":"images-1", 
     "width":"500px", 
     "height":"500px", 
     "top":"0px", 
     "left":"0px", 
     "zIndex":"auto", 
     "img":"http:\/\/192.168.1.156\/dutees\/tshirtecommerce\/\/uploaded\/products\/dg-designer-69b4fa3b144332567968295645910544813.png" 
     } 
    } 
] 

は、だから、IMGデータ、コードの下に使用したい場合:@Mohan

$file = dirname(DIR_SYSTEM) . '/tshirtecommerce/data/products.json'; 

if (file_exists($file)) 
{  
    $string = file_get_contents($file); 
    if ($string != false) 
    { 
    $e_products = json_decode($string, true); 
    if ($e_products) 
    { 
     foreach($e_products as $item) 
     { 
     $first_id = (isset($item[0]) && isset($item[0]['id']) ? $item[0]['id'] : null; 
     $second_id = (isset($item[1]) && isset($item[1]['id']) ? $item[1]['id'] : null; 
     $width  = (isset($item[1]) && isset($item[1]['width']) ? $item[1]['width'] : null; 
     $height = (isset($item[1]) && isset($item[1]['height']) ? $item[1]['height'] : null; 
     $top  = (isset($item[1]) && isset($item[1]['top']) ? $item[1]['top'] : null; 
     $left  = (isset($item[1]) && isset($item[1]['left']) ? $item[1]['left'] : null; 
     $zIndex = (isset($item[1]) && isset($item[1]['zIndex']) ? $item[1]['zIndex'] : null; 
     $img  = (isset($item[1]) && isset($item[1]['img']) ? $item[1]['img'] : null; 
     } 
    } 
} 
} 
+0

いいえ、不正な文字列のオフセットを投げていません。 – Mohan

+0

どこがエラーですか?どのファイルと行にエラーがありますか? –

+0

実際に私の配列でコードをしようとすると、不正な文字列オフセットが表示されます。 '' id ':' images-1 '、' width ':' 500px '、' height ': – Mohan

関連する問題