BinaryContent.CreateJson Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| CreateJson(String, Boolean) |
Creates an instance of BinaryContent that contains the provided JSON string. |
| CreateJson<T>(T, JsonSerializerOptions) |
Creates an instance of BinaryContent that contains the JSON representation of the provided object. |
| CreateJson<T>(T, JsonTypeInfo<T>) |
Creates an instance of BinaryContent that contains the JSON representation of the provided object using the specified JSON type information. |
CreateJson(String, Boolean)
- Source:
- BinaryContent.cs
Creates an instance of BinaryContent that contains the provided JSON string.
public static System.ClientModel.BinaryContent CreateJson(string jsonString, bool validate = false);
static member CreateJson : string * bool -> System.ClientModel.BinaryContent
Public Shared Function CreateJson (jsonString As String, Optional validate As Boolean = false) As BinaryContent
Parameters
- jsonString
- String
The JSON string to be used as the content.
- validate
- Boolean
Whether to validate that the string contains valid JSON. If true, the method will validate the JSON format and throw an exception if invalid. Defaults to false for backwards compatibility.
Returns
An instance of BinaryContent that contains the provided JSON string.
Exceptions
Thrown when validate is true and
jsonString is not valid JSON.
Applies to
CreateJson<T>(T, JsonSerializerOptions)
- Source:
- BinaryContent.cs
Creates an instance of BinaryContent that contains the JSON representation of the provided object.
public static System.ClientModel.BinaryContent CreateJson<T>(T jsonSerializable, System.Text.Json.JsonSerializerOptions? options = default);
static member CreateJson : 'T * System.Text.Json.JsonSerializerOptions -> System.ClientModel.BinaryContent
Public Shared Function CreateJson(Of T) (jsonSerializable As T, Optional options As JsonSerializerOptions = Nothing) As BinaryContent
Type Parameters
- T
The type of the object to serialize.
Parameters
- jsonSerializable
- T
The object to serialize to JSON.
- options
- JsonSerializerOptions
The JsonSerializerOptions to use for serialization. If not provided, the default options will be used.
Returns
An instance of BinaryContent that contains the JSON representation of the provided object.
Applies to
CreateJson<T>(T, JsonTypeInfo<T>)
- Source:
- BinaryContent.cs
Creates an instance of BinaryContent that contains the JSON representation of the provided object using the specified JSON type information.
public static System.ClientModel.BinaryContent CreateJson<T>(T jsonSerializable, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo);
static member CreateJson : 'T * System.Text.Json.Serialization.Metadata.JsonTypeInfo<'T> -> System.ClientModel.BinaryContent
Public Shared Function CreateJson(Of T) (jsonSerializable As T, jsonTypeInfo As JsonTypeInfo(Of T)) As BinaryContent
Type Parameters
- T
The type of the object to serialize.
Parameters
- jsonSerializable
- T
The object to serialize to JSON.
- jsonTypeInfo
- JsonTypeInfo<T>
The JsonTypeInfo<T> to use for serialization.
Returns
An instance of BinaryContent that contains the JSON representation of the provided object.