这是一个php项目。但是不明白什么类型的数据。
我想把它解析为json。
a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}
答案 0 :(得分:3)
它被称为 serialized data
1。 您可以unserialize()将其转换为数组
<?php
$data = 'a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}';
$unserialized_array = unserialize($data);
print_r($unserialized_array);
输出: - https://eval.in/993433
2。 您可以使用json_encode()将其削减为json
<?php
$data = 'a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}';
$json_data = json_encode(unserialize($data));
echo $json_data;
输出: - https://eval.in/993437
答案 1 :(得分:1)
这是序列化数据;您可以使用unserialize获取内容;
$a = 'a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}';
print_r(unserialize($a));
返回:
Array (
[1] => 49
[2] => 53
[3] => 140
[4] => 53
[5] => 53
[6] => 40
[7] => 40
[8] => 60
[9] => 40
[10] =>
)
然后你可以在你现在的序列化数据上运行json_encode()
来获得你想要的输出......
$a = 'a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}';
echo json_encode(unserialize($a));
返回:
{"1":"49","2":"53","3":"140","4":"53","5":"53","6":"40","7":"40","8":"60","9":"40","10":""}
答案 2 :(得分:-1)
它是序列化数据;您可以反序列化它并转换为json;
<?php
$data = 'a:10:{i:1;s:2:"49";i:2;s:2:"53";i:3;s:3:"140";i:4;s:2:"53";i:5;s:2:"53";i:6;s:2:"40";i:7;s:2:"40";i:8;s:2:"60";i:9;s:2:"40";i:10;s:0:"";}';
echo json_encode(unserialize($data));
它是example,只需按下执行即可获得你的json;