rokojori_action_library/Tools/mcp/JsonUtil.cs

26 lines
633 B
C#
Raw Normal View History

2026-10-03 12:15:58 +00:00
#if TOOLS
namespace Rokojori.Tools
{
using Rokojori;
// JSONObject.GetString/GetNumber/GetBoolean etc. call Get(key) and dereference the result
// without a null check - they throw if the key is simply absent, which is the normal case
// for optional/missing request fields. This is the null-safe version for that situation.
public static class JsonUtil
{
public static string GetStringOrNull( JSONObject obj, string key )
{
if ( obj == null )
{
return null;
}
var data = obj.Get( key );
return data != null && data.isString ? data.stringValue : null;
}
}
}
#endif