Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.NET: Serialize json string property into json object

Tags:

People also ask

How do you serialize and deserialize a string in C#?

SerializeObject<MatrixSerializable>(ms); Console. WriteLine("serialized: " + s); ms = Serializer. DeserializeObject<MatrixSerializable>(s); Console. WriteLine("deserialized: " + ms.

How do you serialize a JSON object?

NET objects as JSON (serialize) To write JSON to a string or to a file, call the JsonSerializer. Serialize method. The JSON output is minified (whitespace, indentation, and new-line characters are removed) by default.

How do you serialize and deserialize an object in C# using JSON?

In Deserialization, it does the opposite of Serialization which means it converts JSON string to custom . Net object. In the following code, it calls the static method DeserializeObject() of the JsonConvert class by passing JSON data. It returns a custom object (BlogSites) from JSON data.

How do I string a JSON object?

Stringify a JavaScript ObjectUse the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);


Is it possible to tell JSON.NET I have a string with JSON data? E.g. I have a class like this:

public class Foo {     public int Id;     public string RawData; } 

which I use like this:

var foo = new Foo(); foo.Id = 5; foo.RawData = @"{""bar"":42}"; 

which I want to be serialized like this:

{"Id":5,"RawData":{"bar":42}} 

Basically I have a piece of unstructured variable-length data stored as JSON already, I need fully serialized object to contain this data as a part.

Thanks.

EDIT: Just to make sure it is understood properly, this is one-way serialization, i.e. I don't need it to deserialize back into same object; the other system shall process this output. I need content of RawData to be a part of JSON, not a mere string.