从数组中删除斜杠

时间:2013-09-22 10:18:03

标签: php firebase

Firebase正在踢我的**。我正在尝试使用php

从users表中的列(令牌)

我设置了todo路径

  $todoPath = 'users/'.$userId.'';

获取数据

  $response = $fb->get($todoPath);

并得到这个$响应:

 {"lastName":"Sengbe","location":{"name":"San Francisco,    California","id":"114952118516947"},"timezone":"-7","birthday":"06/25/1978","-  J445njkymYw9INQcvAi":{"lastName":"Bond","location":{"name":"San Francisco,   California","id":"114952118516947"},"tokens":2,"timezone":"-7","birthday":"06/25/1978","userName":"whosesse","name":"James Sengbe","verified":"true","provider":"facebook","gender":"male","email":"james@bond.com","firstName":"James"},"userName":"whosesse","name":"james Bond","verified":"true","provider":"facebook","gender":"male","email":"James@bond.com","firstName":"James"}

现在我想抓住这个令牌。我没有尝试过任何工作

尝试了

 $tokens=$response->{'tokens'}

 $tokens=$response['tokens'];

2 个答案:

答案 0 :(得分:2)

你必须使用json_decode从json字符串中创建一个对象。

$response = json_decode($fb->get($todoPath));

var_dump($response->tokens);

答案 1 :(得分:0)

使用带有第二个参数json_decode的{​​{1}}来创建关联数组然后解析数组

true

输出:

$json = json_decode($response,true);

$tokens = $json["-  J445njkymYw9INQcvAi"]["tokens"]; //based on your response

echo $tokens;