Beispiel #1
0
        public static JsonObject asObject(string jsonString)
        {
            JsonObject jsonObject = null;

            if (!string.ReferenceEquals(jsonString, null))
            {
                try
                {
                    jsonObject = GsonMapper.fromJson(jsonString, typeof(JsonObject));
                }
                catch (Exception e) when(e is JsonParseException || e is System.InvalidCastException)
                {
                    LOG.logJsonException(e);
                }
            }

            if (jsonObject != null)
            {
                return(jsonObject);
            }
            else
            {
                return(createObject());
            }
        }
Beispiel #2
0
        public static JsonObject asObject(sbyte[] byteArray)
        {
            string stringValue = null;

            if (byteArray != null)
            {
                stringValue = StringUtil.fromBytes(byteArray);
            }

            if (string.ReferenceEquals(stringValue, null))
            {
                return(createObject());
            }

            JsonObject jsonObject = null;

            try
            {
                jsonObject = GsonMapper.fromJson(stringValue, typeof(JsonObject));
            }
            catch (JsonParseException e)
            {
                LOG.logJsonException(e);
            }

            if (jsonObject != null)
            {
                return(jsonObject);
            }
            else
            {
                return(createObject());
            }
        }
Beispiel #3
0
        public static object asPrimitiveObject(JsonPrimitive jsonValue)
        {
            if (jsonValue == null)
            {
                return(null);
            }

            object rawObject = null;

            if (jsonValue.Number)
            {
                object numberValue = null;

                try
                {
                    numberValue = jsonValue.AsNumber;
                }
                catch (System.FormatException e)
                {
                    LOG.logJsonException(e);
                }

                if (numberValue != null && numberValue is LazilyParsedNumber)
                {
                    string numberString = numberValue.ToString();
                    if (!string.ReferenceEquals(numberString, null))
                    {
                        rawObject = parseNumber(numberString);
                    }
                }
                else
                {
                    rawObject = numberValue;
                }
            }
            else
            {     // string, boolean
                try
                {
                    rawObject = GsonMapper.fromJson(jsonValue, typeof(object));
                }
                catch (Exception e) when(e is JsonSyntaxException || e is JsonIOException)
                {
                    LOG.logJsonException(e);
                }
            }

            if (rawObject != null)
            {
                return(rawObject);
            }
            else
            {
                return(null);
            }
        }