我是一个php新手,现在在自己写一个简单的借口,在接口文件中返回一个json,
要怎么在另外一个文件中获取json里面的值,这个是我用curl获取到的json
{"key":"testAction","account":"root","weight":"200kg"}
然后我要怎么获取里面的值?比方说单单获取key或者account?
我用$jsContent.key和$jsContent["key"]都不行,要怎么处理这样子的数据,
也试过json_decode,也是不行
json_decode($data, TRUE); 第二个参数加上TRUE会把json数据转成PHP数组
$s='{"key":"testAction","account":"root","weight":"200kg"}';
$o=json_decode($s);
echo $o->key."<br>";
echo $o->account."<br>";
echo $o->weight."<br>";
Cannot use object of type stdClass as array
json数据本身就是一个对象,所以你怎么获取一个对象的数据,就怎么获取json的数据:$json->attr;