Go Parse PHP Serialize to JSON
Repo: https://github.com/harry-1012/Go-PHP-serialize-json
Example source (Chinese characters preserved in sample):
Array( |
Serialized string:
a:1:{i:0;a:3:{s:2:"id";i:1;s:5:"price";i:80;s:4:"name";s:12:"一个名字";}} |
JSON result:
[{"Id":1,"Price":80,"Name":"一个名字"}] |
Core conversion (simplified excerpt):
func (serObj *serObj) Phpserialize2Json(serialize string) string { |
Notes:
- phpserialize decodes into
[]interface{}
and map keys areinterface{}
. - Cast numeric fields carefully; PHP ints become Go
int64
. - After
json.Marshal
, URL unescape to restore multibyte characters.
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Comments