static int __CreateInstance(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (LuaAPI.lua_gettop(L) == 1) { LitJson.JsonMapper gen_ret = new LitJson.JsonMapper(); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to LitJson.JsonMapper constructor!")); }
public static ExploreProtocol Create(ExploreProtocolDataType type, string jsonStr, string context = "") { try { var node = JsonMapper.ToObject(jsonStr); if (node != null) { int device = -1; if (node.ContainsKey("device")) { device = (int)node["device"]; } int mode = -1; if (node.ContainsKey("mode")) { mode = (int)node["mode"]; } int id = -1; if (node.ContainsKey("id")) { id = (int)node["id"]; } int code = -1; if (node.ContainsKey("code")) { code = (int)node["code"]; } string uuid = string.Empty; if (node.ContainsKey("uuid")) { uuid = ((string)node["uuid"]); //.ToLower(); } bool debug = false; if (node.ContainsKey("debug")) { debug = (int)node["debug"] == 1; } ExploreProtocol p = new ExploreProtocol(); p.dataType = type; p.device = device; p.mode = mode; p.id = id; p.code = code; p.uuid = uuid; p.debug = debug; if (node.ContainsKey("data")) { var datas = node["data"]; // it's array of int switch (type) { case ExploreProtocolDataType.DTObject: { p.datas = LitJsonHelper.ParseJsonArray(datas, jsonParam => { LitJsonHelper.SafeConvert(jsonParam, out object result); return(result); }, ArrayHelper <object> .Empty); break; } case ExploreProtocolDataType.DTInt: { p.datas = LitJsonHelper.ParseJsonArray(datas, jsonParam => { LitJsonHelper.SafeConvert(jsonParam, out int result); return(result); }, ArrayHelper <int> .Empty); break; } case ExploreProtocolDataType.DTFloat: { p.datas = LitJsonHelper.ParseJsonArray(datas, jsonParam => { LitJsonHelper.SafeConvert(jsonParam, out float result); return(result); }, ArrayHelper <float> .Empty); break; } } } return(p); } } catch (System.Exception ex) { DebugUtility.LogError(LoggerTags.Module, "Failure to create json data , Context : {0}, Stack : {1}", context, ex.StackTrace); } return(null); }