mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-12 10:46:07 +00:00
fix various little things in the json encode and decode
This commit is contained in:
@@ -551,6 +551,8 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c
|
|||||||
nlohmann::json value;
|
nlohmann::json value;
|
||||||
switch (right.get_type()) {
|
switch (right.get_type()) {
|
||||||
case sol::type::lua_nil:
|
case sol::type::lua_nil:
|
||||||
|
value = nullptr;
|
||||||
|
return;
|
||||||
case sol::type::none:
|
case sol::type::none:
|
||||||
return;
|
return;
|
||||||
case sol::type::poly:
|
case sol::type::poly:
|
||||||
@@ -572,7 +574,11 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c
|
|||||||
value = right.as<std::string>();
|
value = right.as<std::string>();
|
||||||
break;
|
break;
|
||||||
case sol::type::number:
|
case sol::type::number:
|
||||||
value = right.as<double>();
|
if (right.is<int>()) {
|
||||||
|
value = right.as<int>();
|
||||||
|
} else {
|
||||||
|
value = right.as<float>();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case sol::type::function:
|
case sol::type::function:
|
||||||
beammp_lua_warn("unsure what to do with function in JsonEncode, ignoring");
|
beammp_lua_warn("unsure what to do with function in JsonEncode, ignoring");
|
||||||
@@ -582,6 +588,7 @@ static void JsonEncodeRecursive(nlohmann::json& json, const sol::object& left, c
|
|||||||
for (const auto& pair : right.as<sol::table>()) {
|
for (const auto& pair : right.as<sol::table>()) {
|
||||||
if (pair.first.get_type() != sol::type::number) {
|
if (pair.first.get_type() != sol::type::number) {
|
||||||
local_is_array = false;
|
local_is_array = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& pair : right.as<sol::table>()) {
|
for (const auto& pair : right.as<sol::table>()) {
|
||||||
@@ -606,10 +613,11 @@ std::string LuaAPI::MP::JsonEncode(const sol::table& object) {
|
|||||||
for (const auto& pair : object.as<sol::table>()) {
|
for (const auto& pair : object.as<sol::table>()) {
|
||||||
if (pair.first.get_type() != sol::type::number) {
|
if (pair.first.get_type() != sol::type::number) {
|
||||||
is_array = false;
|
is_array = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& entry : object) {
|
for (const auto& [key, value] : object) {
|
||||||
JsonEncodeRecursive(json, entry.first, entry.second, is_array);
|
JsonEncodeRecursive(json, key, value, is_array);
|
||||||
}
|
}
|
||||||
return json.dump();
|
return json.dump();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user