对象到阵列转换

时间:2015-02-22 13:03:11

标签: php arrays json object

我使用this库来读取/写入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_decodeexpects parameter 1 to be string, object given)的数组,也无法迭代table_arr,因为它是受保护的数组。

1 个答案:

答案 0 :(得分:0)

为此废弃了图书馆:

$csv = array_map('str_getcsv', file('test.csv'));