The exception thrown when an error occurs during JSON serialization or deserialization.
Inheritance: Newtonsoft.Json.JsonException
Esempio n. 1
0
        public Bill DeserializeJson(string json, out JsonSerializationException deserializationException)
        {
            //Set the output paramater to the desired value (null)
            deserializationException = null;

            try
            {
                //Try and deserialize the json into the Bill object, return the Bill is successful.
                Bill bill = JsonConvert.DeserializeObject<Bill>(json);
                return bill;
            }
            catch (JsonSerializationException exception)
            {
                //Assign the exception to the output parameter
                deserializationException = exception;
            }

            return null;
        }
Esempio n. 2
0
        /// <summary>
        /// Populates the object with values from the JSON string using <see cref="JsonSerializerSettings"/>.
        /// </summary>
        /// <param name="value">The JSON to populate values from.</param>
        /// <param name="target">The target object to populate values onto.</param>
        /// <param name="settings">
        /// The <see cref="JsonSerializerSettings"/> used to deserialize the object.
        /// If this is <c>null</c>, default serialization settings will be used.
        /// </param>
        public static void PopulateObject(string value, object target, JsonSerializerSettings settings)
        {
            JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);

            using (JsonReader jsonReader = new JsonTextReader(new StringReader(value)))
            {
                jsonSerializer.Populate(jsonReader, target);

                if (settings != null && settings.CheckAdditionalContent)
                {
                    while (jsonReader.Read())
                    {
                        if (jsonReader.TokenType != JsonToken.Comment)
                        {
                            throw JsonSerializationException.Create(jsonReader, "Additional text found in JSON string after finishing deserializing object.");
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 // Token: 0x06000C3A RID: 3130 RVA: 0x0000F2B7 File Offset: 0x0000D4B7
 internal static JsonSerializationException Create(JsonReader reader, string message, [Nullable(2)] Exception ex)
 {
     return(JsonSerializationException.Create(reader as IJsonLineInfo, reader.Path, message, ex));
 }
Esempio n. 4
0
 // Token: 0x06000C39 RID: 3129 RVA: 0x0000F2AD File Offset: 0x0000D4AD
 internal static JsonSerializationException Create(JsonReader reader, string message)
 {
     return(JsonSerializationException.Create(reader, message, null));
 }
 private Boolean TestIfNullValueProducesTheException(JsonSerializationException jsonex)
 {
     return jsonex.Message.ToUpper().Contains("NULL");
 }