ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
JSONParser.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SimpleExcel\Parser;
4 
6 
13 class JSONParser extends BaseParser implements IParser
14 {
21  protected $file_extension = 'json';
22 
28  public function loadFile($file_path) {
29 
30  if (!$this->isFileReady($file_path)) {
31  return;
32  }
33 
34  $handle = fopen($file_path, 'r');
35  $this->loadString($handle);
36  fclose($handle);
37  }
38 
45  public function loadString($str){
46  $field = array();
47  if (($table = json_decode(utf8_encode($str), false, 4)) === NULL) {
48  throw new \Exception('Invalid JSON format: '.$str, SimpleExcelException::MALFORMED_JSON);
49  } else {
50  foreach ($table as $rows) {
51  $row = array();
52  foreach ($rows as $cell) {
53  array_push($row, $cell);
54  }
55  array_push($field, $row);
56  }
57  }
58  $this->table_arr = $field;
59  }
60 }