The Bridge.Newtonsoft.Json package provides Bridge.NET support for a limited subset of the Newtonsoft.Json API. See it working on Deck.NET.
IMPORTANT: Only the features listed below are supported.
Install using NuGet:
Install-Package Bridge.Newtonsoft.Json
Serializes the specified object to a JSON string.
Original SerializeObject documentation from Newtonsoft.Json.
Supported | Name | Description |
---|---|---|
SerializeObject(Object) | Serializes the specified object to a JSON string. | |
SerializeObject(Object, Formatting) | Serializes the specified object to a JSON string using formatting. | |
SerializeObject(Object, JsonSerializerSettings | Serializes the specified object to a JSON string using JsonSerializerSettings. | |
SerializeObject(Object, Formatting, JsonSerializerSettings) | Serializes the specified object to a JSON string using formatting and JsonSerializerSettings. | |
SerializeObject(Object, JsonConverter[]) | Serializes the specified object to a JSON string using a collection of JsonConverter. | |
SerializeObject(Object, Formatting, JsonConverter[]) | Serializes the specified object to a JSON string using formatting and a collection of JsonConverter. | |
SerializeObject(Object, Type, JsonSerializerSettings) | Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings. | |
SerializeObject(Object, Type, Formatting, JsonSerializerSettings) | Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings. |
Product product = new Product();
product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string output = JsonConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "ExpiryDate": "2008-12-28T00:00:00",
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
Deserializes the JSON to a .NET object.
Original DeserializeObject documentation from Newtonsoft.Json.
Supported | Name | Description |
---|---|---|
DeserializeObject(String) | Deserializes the JSON to a .NET object. | |
DeserializeObject(String) | Deserializes the JSON to the specified .NET type. | |
DeserializeObject(String, JsonSerializerSettings) | Deserializes the JSON to a .NET object using JsonSerializerSettings. | |
DeserializeObject(String, JsonSerializerSettings) | Deserializes the JSON to the specified .NET type using JsonSerializerSettings. | |
DeserializeObject(String, Type) | Deserializes the JSON to the specified .NET type. | |
DeserializeObject(String, Type, JsonSerializerSettings) | Deserializes the JSON to the specified .NET type using JsonSerializerSettings. | |
DeserializeObject(String, JsonConverter[]) | Deserializes the JSON to the specified .NET type using a collection of JsonConverter. | |
DeserializeObject(String, Type, JsonConverter[]) | Deserializes the JSON to the specified .NET type using a collection of JsonConverter. |
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
https://deck.net/newtonsoft.json
public class Program
{
public static void Main()
{
Product product = new Product();
product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string output = JsonConvert.SerializeObject(product, Formatting.Indented);
// Write the json string
Console.WriteLine(output);
// Deserialize the json back into a real Product
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
// Write the properties
Console.WriteLine(deserializedProduct.Name);
Console.WriteLine(deserializedProduct.ExpiryDate);
Console.WriteLine(deserializedProduct.Price);
Console.WriteLine(deserializedProduct.Sizes);
}
}
public class Product
{
public string Name { get; set; }
public DateTime ExpiryDate { get; set; }
public decimal Price { get; set; }
public string[] Sizes { get; set; }
}
Specifies formatting options for the JsonTextWriter.
Original Formatting documentation from Newtonsoft.Json.
Supported | Name | Value | Description |
---|---|---|---|
None | 0 | No special formatting is applied. This is the default. | |
Indented | 1 | Causes child objects to be indented according to the Indentation and IndentChar settings. |
Original JsonSerializerSettings documentation from Newtonsoft.Json.
Original ContractResolver documentation from Newtonsoft.Json.
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
Specifies type name handling options for the JsonSerializer.
Original TypeNameHandling documentation from Newtonsoft.Json.
Specifies null value handling options for the JsonSerializer.
Original NullValueHandling documentation from Newtonsoft.Json.
Supported | Name | Value | Description |
---|---|---|---|
Include | 0 | Include null values when serializing and deserializing objects. | |
Ignore | 1 | Ignore null values when serializing and deserializing objects. |
Instructs the JsonSerializer to use the specified constructor when deserializing that object.
Original JsonConstructor documentation from Newtonsoft.Json.
https://deck.net/5adc821b73491a122a51fd229ee1a8d3
using System;
using Newtonsoft.Json;
public class Program
{
public static void Main(string[] args)
{
var x = Message.Empty.Add("abc");
var json = JsonConvert.SerializeObject(x);
Console.WriteLine(json);
var cloneX = JsonConvert.DeserializeObject<Message>(json);
Console.WriteLine(cloneX.Value);
}
}
public class Message
{
static Message _empty = new Message("");
public static Message Empty
{
get
{
return _empty;
}
private set
{
_empty = value;
}
}
private Message(bool value) { }
[JsonConstructor]
private Message(string value)
{
Value = value;
}
public string Value { get; private set; }
public Message Add(string value)
{
return new Message(Value + value);
}
}