2017-05-23 6 views
0

Ich habe ein multidimensionales Array, ich möchte 'img' Daten aus dem Array bekommen.So erhalten Sie Bilddaten aus Array

Unten ist mein resultierende Array,

"{'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'}}" 

Below-Code ist,

$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

@Mohan Ihre 'JSON' nicht gültig ist. –

+0

überprüfen Sie bitte Ihre JSON seine ungültige [http://jsonviewer.stack.hu/] –

+0

Ich denke, JSON Schlüssel und Werte sind in doppelte Anführungszeichen – JYoThI

Antwort

0

Sie json ist ungültig! Ich konvertieren gültig:

[ 
    { 
     "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" 
     } 
    } 
] 

Also, wenn Sie wollen img Daten, verwenden Sie unten Code:

$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

Nein, es funktioniert nicht werfen ungültige Zeichenfolge Offset. – Mohan

+0

Wo ist der Fehler? Welche Datei und Zeile hat einen Fehler? –

+0

Eigentlich Wenn ich Code mit meinem Array versuche, zeigt es ungültige String-Offset. – Mohan

Verwandte Themen