以可读格式打印编码或解码的json

时间:2016-07-23 18:54:27

标签: php arrays json human-readable plaid

我使用php curl从格子api获取帐户和交易数据。我想以一种很好的格式看到它,所以我可以创建循环来将信息保存到数据库中。当使用print_r打印时,解码的json输出将返回如下:

array ( [accounts] => Array ( [0] => Array ( [_id] => QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA [_user] => eJXpMzpR65FP4RYno6rzuA7OZjd9n3Hna0RYa [balance] => Array ( [available] => 1203.42 [current] => 1274.93 ) [institution_type] => fake_institution [meta] => Array ( [name] => Plaid Savings [number] => 9606 ) [subtype] => savings [type] => depository ) [1] => Array ( [_id] => nban4wnPKEtnmEpaKzbYFYQvA7D7pnCaeDBMy [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA...

我希望看起来像这样:

Array ( 
    [accounts] => Array ( 
        [0] => Array ( 
            [_id] => QPO8Jo8vdDHMepg41PBwckXm4KdK1yUdmXOwK 
            [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA 
            [_user] => eJXpMzpR65FP4RYno6rzuA7OZjd9n3Hna0RYa 
            [balance] => Array ( 
                [available] => 1203.42 
                [current] => 1274.93 ) 
            [institution_type] => fake_institution 
            [meta] => Array ( 
                [name] => Plaid Savings 
                [number] => 9606 ) 
            [subtype] => savings 
            [type] => depository ) 
        [1] => Array ( 
            [_id] => nban4wnPKEtnmEpaKzbYFYQvA7D7pnCaeDBMy 
            [_item] => KdDjmojBERUKx3JkDd9RuxA5EvejA4SENO4AA 
            `

供参考,以下是获得回复的代码:

$data = array(
    "client_id"=>"test_id",
    "secret"=>"test_secret",
    "access_token"=>"test_chase"
);

$string = http_build_query($data);

//initialize session
$ch=curl_init("https://tartan.plaid.com/connect/get");

//set options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute session
$accountData = json_decode(curl_exec($ch), true);
print_r($accountData);      
//close session
curl_close($ch);

除了循环以外的任何想法?

0 个答案:

没有答案