Serialize PHP => Unserialize JAVA / Serialize for php in string format -
i have array in php of format:
<?php $value = array("id" => 42, "user" => "superman"); echo serialize($value); ?>
serialized :
a:2:{s:2:"id";i:42;s:4:"user";s:8:"superman";}
i receive string
in java. how can deserialize in java ? know implements serializable
in java not work in case.
i want create object in kind of format :
import java.io.serializable; public class serial implements serializable{ private int mid; private string muser; public serial(int mid, string muser) { super(); this.mid = mid; this.muser = muser; } public int getid() { return mid; } public void setid(int id) { this.mid = id; } public string getuser() { return muser; } public void setuser(string user) { this.muser = user; } }
after want create time string
serialized java object deserialize in php;
thanks help.
you can't natively read 1 languages serialised objects language (languages each have own serialisation protocols/format, there no guarantee can read one-anothers format), java serialised objects serialised binary format , php provided text format.
there libraries such google's protocol buffers can use, don't officially support php, there 3rd party libraries provide protocol buffer support php.
protocol buffers google's language-neutral, platform-neutral, extensible mechanism serializing structured data – think xml, smaller, faster, , simpler. define how want data structured once, can use special generated source code write , read structured data , variety of data streams , using variety of languages – java, c++, or python.
if aren't fond of that, need develop own protocol reading phps serialised objects java object, may able modified json library don't believe s:2:"id";
sample serialised object valid json. there exists library doing using java, php serialisation format isn't 'safe' can contain null values, advise against it.
Comments
Post a Comment