简体   繁体   English

如何在php中将以下字符串解析为json

[英]how to parse the following string to json in php

I need small as key and url as value for example :-我需要小作为keyurl作为值,例如:-

small->upload\\2016\\04\\greenfield-100x100.jpg小->上传\\2016\\04\\greenfield-100x100.jpg

"a:3:{s:5:\"small\";s:39:\"\/uploads\/2016\/04\/greenfield-100x100.jpg\";s:6:\"medium\";s:39:\"\/uploads\/2016\/04\/greenfield-300x200.jpg\";s:5:\"large\";s:39:\"\/uploads\/2016\/04\/greenfield-500x400.jpg\";}"" 

You need to use unserialize for getting the data as Readable / Understandable.您需要使用反unserialize来获取可读/ unserialize的数据。 Your data is valid.您的数据有效。

unserialize() takes a single serialized variable and converts it back into a PHP value. unserialize()接受单个序列化变量并将其转换回 PHP 值。

$data = "a:3:{s:5:\"small\";s:39:\"/uploads/2016/04/greenfield-100x100.jpg\";s:6:\"medium\";s:39:\"/uploads/2016/04/greenfield-300x200.jpg\";s:5:\"large\";s:39:\"/uploads/2016/04/greenfield-500x400.jpg\";}";
$out = unserialize($data);
print_r($out);

The Result after unserialize .unserialize后的结果。

Array
(
    [small] => /uploads/2016/04/greenfield-100x100.jpg
    [medium] => /uploads/2016/04/greenfield-300x200.jpg
    [large] => /uploads/2016/04/greenfield-500x400.jpg
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM