我正在尝试从JSON请求中获取“id”值。但我收到此错误未定义的属性:stdClass :: $ id Laravel。
$data = json_decode($request->getContent());
foreach ($data->data as $data){
$id = $data->id;
$modsyPrice = floor($data->modsyPrice);
}
这是我的Json:
{"data":{"0":{"ID":"1","Name":"3 Piece Roundabout Candle Holders","Url":
"http://url","ModsyStatus":"0","weRplayStatus"
:"0", "ModsyPrice" :"39.95", "weRplayPrice":"39.95","activeLoader":true} }}
答案 0 :(得分:1)
ID
:$id = $data->ID;
与ModsyPrice
答案 1 :(得分:0)
尝试如下:您的数组是多维的。
/*$json = '{"data":{"0":{"ID":"1","Name":"3 Piece Roundabout Candle Holders","Url":
"http://url","ModsyStatus":"0","weRplayStatus"
:"0", "ModsyPrice" :"39.95", "weRplayPrice":"39.95","activeLoader":true} }}';*/
$json =json_decode($request->getContent(),true); //get your json
$array = json_decode($json,true);
//print_r($array);
foreach ($array['data'] as $data){
$id = $data['ID'];
$modsyPrice = floor($data['ModsyPrice']);
}
echo $id."<br/>";
echo $modsyPrice;