对象到数组的转换
Object to Array conversion
我正在使用 this 库来 read/write CSV 文件:
$csv = new SimpleExcel('CSV');
$csv->parser->loadFile('test.csv');
$csv->convertTo('JSON');
输出是一个对象:
SimpleExcel\SimpleExcel Object
(
[parser] => SimpleExcel\Parser\CSVParser Object
(
[delimiter:protected] => ,
[file_extension:protected] => csv
[table_arr:protected] => Array
(
[0] => Array
(
[0] => Title
[1] => COST PRICE
[2] => REGULAR POST
[3] => REGISTERED POST
[4] => EXPRESS POST
)
...
...但我无法将其转换为具有 json_decode
(expects parameter 1 to be string, object given
) 的数组,也无法遍历 table_arr
,因为它是一个受保护的数组。
为此废弃了库:
$csv = array_map('str_getcsv', file('test.csv'));
我正在使用 this 库来 read/write CSV 文件:
$csv = new SimpleExcel('CSV');
$csv->parser->loadFile('test.csv');
$csv->convertTo('JSON');
输出是一个对象:
SimpleExcel\SimpleExcel Object
(
[parser] => SimpleExcel\Parser\CSVParser Object
(
[delimiter:protected] => ,
[file_extension:protected] => csv
[table_arr:protected] => Array
(
[0] => Array
(
[0] => Title
[1] => COST PRICE
[2] => REGULAR POST
[3] => REGISTERED POST
[4] => EXPRESS POST
)
...
...但我无法将其转换为具有 json_decode
(expects parameter 1 to be string, object given
) 的数组,也无法遍历 table_arr
,因为它是一个受保护的数组。
为此废弃了库:
$csv = array_map('str_getcsv', file('test.csv'));