php解析JSON

直接贴代码,两种方式:

$data = '[{"id":"2801370344505508","order":0},{"id":"2801370745841539","order":1},{"id":"2801370745836594","order":2}]';

方式1
$order =  json_decode($data);  //返回对象哦
foreach($order as $k => $v){
print_r($v->id."".$v->order);
}

方式2
$order = json_decode($data,true);  //第二个参数 true,返回的是数组
foreach($order as $k => $v){
$this->db_group->update(array("ord_idx"=>$v[order]),array("id"=>$v[id]));

你可能感兴趣的:(php解析JSON)