当前位置: 首页 > 工具软件 > PHP Serialize > 使用案例 >

java序列化php serialize、unserialize

晋鹤轩
2023-12-01

导入包

<dependency>
   <groupId>org.sction</groupId>
   <artifactId>phprpc</artifactId>
   <version>3.0.2</version>
</dependency>

顶部导入

import org.phprpc.util.AssocArray;
import org.phprpc.util.PHPSerializer;

反序列化unserialize

    public Result repairid(@RequestParam Map searchMap) throws Exception{
        String rid = searchMap.get("id").toString();
        List<Map> list = repairService.repairid(rid);
        PHPSerializer p = new PHPSerializer();//new php
        String content = null;
        for (int i=0;i<list.size();i++){
            HashMap<String,Object> map = (HashMap<String, Object>) list.get(i);//数组一维
            //String serializeString  = "a:3:{i:0;s:6:"张三";i:1;s:6:"李四";i:2;s:6:"王五";}";
            content = map.get("content_img").toString();//序列化数据
            Object unserialize = p.unserialize(content.getBytes("utf-8"));//数据转格式
            AssocArray array = (AssocArray) unserialize;
            List<Object> listResult = new ArrayList<Object>();
            for (int s = 0; s < array.size(); s++) {
                listResult.add(new String((byte[])array.get(s)));
            }
            map.put("imgss",listResult);
            list.set(i,map);
        }
        return new Result(true,StatusCode.OK,"查询成功",list);
    }

 

 

 类似资料: