我无法访问通过curl返回的数据。数据作为复杂字符串返回。我说复杂,因为它使用花括号,它看起来像一个数组。
我尝试像访问数组一样访问数据,例如。 $var['key']
,但这给了我一个错误:
WARNING: Illegal string offset
以下是通过curl返回的内容:
string(1422) "{"transactions":
[{"transaction_id":143720,"currency_adjustment":20,"offer_id":null,"offer_name":null,"description":"Cash Out","timestamp":"11\/19\/14"},
{"transaction_id":143718,"currency_adjustment":-10,"offer_id":null,"offer_name":null,"description":"Cash Out","timestamp":"11\/19\/14"},
{"transaction_id":143716,"currency_adjustment":-10,"offer_id":null,"offer_name":null,"description":"Cash Out","timestamp":"11\/19\/14"},
{"transaction_id":143672,"currency_adjustment":0.1,"offer_id":null,"offer_name":null,"description":"Referral Earnings","timestamp":"11\/19\/14"}]}"
我希望获得currency_adjustment
的访问权限。
我试着这样做:
$response['currency_adjustment']
& {$response['currency_adjustment']}
如何访问此字符串中的数据?
答案 0 :(得分:0)
答案 1 :(得分:0)
$result = (array)json_decode($response);
$data = $result["transactions"];
echo $data[0]["currency_adjustment"];