-1

Firebase 正在踢我的**。我正在尝试使用 php 从用户表中获取一列(令牌)

我设置了待办事项路径

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

获取数据

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

并得到这个 $response:

 {"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'];
4

2 回答 2

2

您必须使用json_decodejson 字符串来制作对象。

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

var_dump($response->tokens);
于 2013-09-22T10:20:29.170 回答
0

json_decode与第二个参数一起使用true创建关联数组然后解析数组

$json = json_decode($response,true);

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

echo $tokens;

输出:

2
于 2013-09-22T10:36:04.173 回答