我正在使用 php curl 从格子 api 获取帐户和交易数据。我希望以一种不错的格式查看它,以便我可以创建循环以将信息保存到数据库中。解码后的 json 输出,当使用 print_r 打印时,返回如下:
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);
除了循环还有什么想法吗?