简体   繁体   English

laravel 4获取给定密钥的JSON值

[英]laravel 4 get a JSON value for a given key

I'm using: 我正在使用:

$location = file_get_contents($mapurl);

which responds with json: 用json响应:

{
  "results" : [],
  "status" : "ZERO_RESULTS"
}

how can I extract a value for a given key ? 如何提取给定键的值?

I've tried: 我试过了:

$status = $location::get('status');

but this is throwing errors. 但这会引发错误。

Try 尝试

$location = json_decode(file_get_contents($mapurl));
$status = $location->status;

file_get_contents returns a string, you have to call json_decode convert it to an object then you can access the status property. file_get_contents返回一个字符串,您必须调用json_decode将其转换为对象,然后才能访问status属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM