{ 'status':'200', 'message':'ok','updatetime':'2012-10-05 12:46:21','ischeck':'1','com':'yuantong','nu':'2636535819','state':'3','condition':'F00','data':[ {'time':'2012-07-09 13:22:02','context':'北京市海淀区中关村鼎好/PDA正常签收扫描/签收人:医院收发室 ','ftime':'2012-07-09 13:22:02'},{'time':'2012-07-08 12:39:58','context':'北京市海淀区中关村鼎好/留仓件入扫描节假日客户休息 ','ftime':'2012-07-08 12:39:58'},{'time':'2012-07-08 12:35:01','context':'北京市海淀区中关村鼎好/派件扫描/派件人:王一民 ','ftime':'2012-07-08 12:35:01'},{'time':'2012-07-08 11:05:08','context':'北京市海淀区中关村鼎好/下车扫描 ','ftime':'2012-07-08 11:05:08'},{'time':'2012-07-08 06:53:20','context':'北京市海淀区中关村/装件入车扫描 ','ftime':'2012-07-08 06:53:20'},{'time':'2012-07-08 05:09:31','context':'北京分拨中心/装件入车扫描 ','ftime':'2012-07-08 05:09:31'},{'time':'2012-07-07 22:26:21','context':'北京分拨中心/装件入车扫描 ','ftime':'2012-07-07 22:26:21'},{'time':'2012-07-07 22:22:13','context':'北京分拨中心/拆包扫描 ','ftime':'2012-07-07 22:22:13'},{'time':'2012-07-07 20:01:34','context':'北京市通州区城区/揽收扫描/取件人:王昌征 ','ftime':'2012-07-07 20:01:34'},{'time':'2012-07-07 17:35:24','context':'北京市通州区城区/业务员收件/取件人:张蒙 ','ftime':'2012-07-07 17:35:24'}]} 想提取message的值,如此处是ok,还有最有一条记录的时间和内容,如此处分别是2012-07-07 17:35:24和北京市通州区城区/业务员收件/取件人:张蒙,该如何实现?

解决方案 »

  1.   

    假定编码为utf-8的,否则还需$s=iconv('gbk', 'utf-8', $s);$s = 你的那个串
    $s = strtr($s, "'", '"'); //转成php可识别的 json
    $t = json_decode($s);
    echo $t->message; //ok
    echo $t->data[9]->context; //北京市通州区城区/业务员收件/取件人:张蒙
      

  2.   


    $current= strtr($current0, "'", '"');
    $json = json_decode($current);
    echo $json->message;
    $length=count($json->data);;
    $bottom=$length-1;
    echo $json->data[$bottom]->context;