0

using JavaScriptSerializer we serialize like this:

var serializer = new JavaScriptSerializer();

string requestData = serializer.Serialize(new
{
   EventID = 1,
   SubscriberID = 5,
   ToList = "abcd",
   TemplateParamVals = ""
 });

How do I do the same using Json.NET? The var serializer will be used in UploadDataTaskAsync method of WebClient.

1

1 Answer 1

2

If you want to serialize to a string, you can use the static methods in the JsonConvert class.

string requestData = JsonConvert.SerializeObject(new
{
   EventID = 1,
   SubscriberID = 5,
   ToList = "abcd",
   TemplateParamVals = ""
 });

To serialize to a JsonWriter or TextWriter, use the JsonSerializer class.

var serializer = new JsonSerializer();
serializer.Serialize(writer, obj);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.