Unserialize in Java a serialized php object

前端 未结 15 1092
闹比i
闹比i 2020-11-29 11:31

Does anyone know if it is possible, actually if it has been done, to serialize an object in php and unserialize it in Java (java-php communication). Maybe an adapter will be

15条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 12:04

    Another Java project to work with the PHP serialization format is Pherialize.

    Let's say you are serializing an array like this:

    array(3) {
      [0]=>
      string(8) "A string"
      [1]=>
      int(12345)
      [2]=>
      bool(true)
    }
    

    Then you can unserialize it in Java with Pherialize like this:

    MixedArray list = Pherialize.unserialize(data).toArray();
    System.out.println("Item 1: " + list.getString(0));
    System.out.println("Item 2: " + list.getInteger(1));
    System.out.println("Item 3: " + list.getBoolean(2));
    

提交回复
热议问题