function data2lua($data)
{
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$lists = mbStrSplit($data);
$length = count($lists);
$frontPos = -1;
$i = 0;
for ($i = 0; $i < count($lists); $i++) {
$one = $lists[$i];
if ($one == '[') {
$lists[$i] = '{';
} else if ($one == ']') {
$lists[$i] = '}';
} else if ($one == '"' and $i < ($length - 1) and $lists[$i + 1] != ':') {
$frontPos = $i;
} else if ($one == ':' and $i >= 2 and $lists[$i - 1] == '"' and $lists[$i - 2] != ':' and $frontPos > -1) {
$lists[$frontPos] = '["';
$lists[$i - 1] = '"]';
$lists[$i] = "=";
$frontPos = -1;
}
}
$lists = join($lists, "");
return $lists;
}
JSON 转lua table php版
点赞
收藏