mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 16:25:36 +00:00
Fix Util.JsonEncode
This commit is contained in:
parent
8d57db4a23
commit
ecf06bf1c9
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
@ -239,9 +240,7 @@ class Util:
|
|||||||
|
|
||||||
def _recursive_dict_encode(self, table):
|
def _recursive_dict_encode(self, table):
|
||||||
for k, v in table.items():
|
for k, v in table.items():
|
||||||
if not isinstance(v, (int, float, bool, str, dict, list)) and \
|
if not isinstance(v, (int, float, bool, str, dict, list)) and "LuaTable" not in str(type(v)):
|
||||||
"LuaTable" not in str(type(v)) or \
|
|
||||||
"object at 0x" in str(repr(v)):
|
|
||||||
table[k] = None
|
table[k] = None
|
||||||
continue
|
continue
|
||||||
if "LuaTable" in str(type(v)):
|
if "LuaTable" in str(type(v)):
|
||||||
@ -256,8 +255,10 @@ class Util:
|
|||||||
def JsonEncode(self, table):
|
def JsonEncode(self, table):
|
||||||
self.log.debug("requesting JsonEncode()")
|
self.log.debug("requesting JsonEncode()")
|
||||||
if all(isinstance(k, int) for k in table.keys()):
|
if all(isinstance(k, int) for k in table.keys()):
|
||||||
return f"{self._recursive_list_encode(table)}"
|
data = self._recursive_list_encode(table)
|
||||||
return f"{self._recursive_dict_encode(table)}"
|
else:
|
||||||
|
data = self._recursive_dict_encode(table)
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
def JsonDecode(self, string):
|
def JsonDecode(self, string):
|
||||||
self.log.debug("requesting JsonDecode()")
|
self.log.debug("requesting JsonDecode()")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user