コード例 #1
0
 /// <summary>
 /// 将 json 字符串转换成字典
 /// </summary>
 /// <param name="jsonStr"></param>
 /// <returns>字典对象,如果不能转换则返回 null。</returns>
 public static Dictionary <string, object> Parse2Dictionary(string jsonStr)
 {
     if (jsonStr == null)
     {
         return(null);
     }
     try
     {
         return(MiniJSON.Json.Deserialize(jsonStr) as Dictionary <string, object>);
     }
     catch (Exception ex)
     {
         SALog.Error(ex.Message);
     }
     return(null);
 }
コード例 #2
0
 /// <summary>
 /// 将字符串转换成 Java JSONObject 对象
 /// </summary>
 /// <param name="jsonStr">json 字符串</param>
 /// <returns>AndroidJavaObject,如果不能成功转换则会返回 null</returns>
 public static AndroidJavaObject Parse2JavaJSONObject(string jsonStr)
 {
     if (jsonStr == null || "null".Equals(jsonStr))
     {
         return(null);
     }
     try
     {
         return(new AndroidJavaObject("org.json.JSONObject", jsonStr));
     }
     catch (Exception e)
     {
         SALog.Error("Can not parse " + jsonStr + "to JSONObject: " + e);
     }
     return(null);
 }
コード例 #3
0
 /// <summary>
 /// 将字典转换成 Json 字符串
 /// </summary>
 /// <param name="dictionary">字典</param>
 /// <returns>json 字符串,如果字典不能转换成字符串那么会返回 null。</returns>
 public static string Parse2JsonStr(Dictionary <string, object> dictionary)
 {
     if (dictionary == null)
     {
         return(null);
     }
     try
     {
         return(MiniJSON.Json.Serialize(dictionary));
     }
     catch (Exception e)
     {
         SALog.Error(e.Message);
     }
     return(null);
 }
コード例 #4
0
 /// <summary>
 /// 判断字典的 value 是否为支持的类型,当前支持 string,number,DateTime
 /// </summary>
 /// <param name="dic">event properties dictionary</param>
 /// <returns>合规就返回 true,否则返回 false</returns>
 public static bool AssertValue(Dictionary <string, object> dic)
 {
     if (dic == null)
     {
         return(true);
     }
     foreach (var value in dic.Values)
     {
         if (!(value is string || IsNumeric(value) || value is DateTime))//TODO 此处校验不全
         {
             SALog.Error("The property values must be an instance of string, number or DateTime");
             return(false);
         }
     }
     return(true);
 }
コード例 #5
0
        /// <summary>
        /// 判断事件的 key 值是否合规
        /// </summary>
        /// <param name="key">event key</param>
        /// <returns>合规就返回 true,否则返回 false</returns>
        public static bool AssertKey(string key)
        {
            if (key == null || key.Length == 0)
            {
                SALog.Error("The key is empty.");
                return(false);
            }
            if (key.Length > 255)
            {
                SALog.Error("The key [" + key + "] is too long, max length is 255.");
                return(false);
            }

            if (KEY_PATTERN.IsMatch(key))
            {
                return(true);
            }
            else
            {
                SALog.Error("The key [" + key + "] is invalid.");
                return(false);
            }
        }