2016-04-29 13 views
-1

JSONファイルで作業を始めたばかりで、値 "text"を取得する方法を知る必要があります。基本的にその私はそれを言う必要を走る完了時:PHPはjsonから巨大な多値配列の値を取得します

私のJSONコンテンツ「WEがなかった場合、我々を行うことができるすべてのものは、文字通り自分自身を仰天WOULD」:また

{ 
    "language": "en", 
    "textAngle": 0, 
    "orientation": "Up", 
    "regions": [{ 
     "boundingBox": "791,118,592,838", 
     "lines": [{ 
      "boundingBox": "799,118,453,58", 
      "words": [{ 
       "boundingBox": "799,118,102,58", 
       "text": "IF" 
      }, { 
       "boundingBox": "937,119,109,57", 
       "text": "WE" 
      }, { 
       "boundingBox": "1087,118,165,58", 
       "text": "DID" 
      }] 
     }, { 
      "boundingBox": "792,184,512,176", 
      "words": [{ 
       "boundingBox": "792,184,512,176", 
       "text": "ALL" 
      }] 
     }, { 
      "boundingBox": "796,368,515,60", 
      "words": [{ 
       "boundingBox": "796,368,155,59", 
       "text": "THE" 
      }, { 
       "boundingBox": "993,368,318,60", 
       "text": "THINGS" 
      }] 
     }, { 
      "boundingBox": "791,441,312,57", 
      "words": [{ 
       "boundingBox": "791,441,108,57", 
       "text": "WE" 
      }, { 
       "boundingBox": "937,441,166,57", 
       "text": "ARE" 
      }] 
     }, { 
      "boundingBox": "797,508,586,87", 
      "words": [{ 
       "boundingBox": "797,508,586,87", 
       "text": "CAPABLE" 
      }] 
     }, { 
      "boundingBox": "795,607,452,72", 
      "words": [{ 
       "boundingBox": "795,607,106,59", 
       "text": "OF" 
      }, { 
       "boundingBox": "941,607,306,72", 
       "text": "DOING," 
      }] 
     }, { 
      "boundingBox": "791,678,424,60", 
      "words": [{ 
       "boundingBox": "791,680,108,57", 
       "text": "WE" 
      }, { 
       "boundingBox": "937,678,278,60", 
       "text": "WOULD" 
      }] 
     }, { 
      "boundingBox": "793,750,498,59", 
      "words": [{ 
       "boundingBox": "793,750,498,59", 
       "text": "LITERALLY" 
      }] 
     }, { 
      "boundingBox": "791,821,390,60", 
      "words": [{ 
       "boundingBox": "791,821,390,60", 
       "text": "ASTOUND" 
      }] 
     }, { 
      "boundingBox": "795,893,531,63", 
      "words": [{ 
       "boundingBox": "795,893,531,63", 
       "text": "OURSELVES." 
      }] 
     }] 
    }] 
} 

を非常に記述的ではないことを申し訳ありませんが、私はStackOverflowにとって非常に新しいです。

+1

何か試しましたか?私たちにいくつかのコードを表示し、改善するためにあなたを助けることができます/それを修正してください。しかし、私たちはコードを書くつもりはありません。 – olibiaz

+0

この回答を確認するhttp://stackoverflow.com/a/18362216/6127393 –

+0

私は@olibiazに同意します:これはちょっとしたトラバーサルなので、試したことを示してください。 –

答えて

1

さらに一般的な回答がありますが、このコードはJSONに適しています。 textが格納されている適切なレベルに到達しようとしています。 JSONの各レベルはforeachの別のレベルです。

$json = '{ "language": "en" ... '; 

$decoded = json_decode($json, true); 

$result = ""; 

foreach($decoded['regions'] as $region) { 
    foreach($region['lines'] as $lines) { 
    foreach($lines["words"] as $words) { 
     $result .= $words["text"] . " "; 
    }  
    } 
} 

echo $result; 
+0

完全に動作します<3 +1 – Techwizmatt

関連する問題