Reputation: 24572
I am trying to serialize an object with Newtonsoft Json converter like this:
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Newtonsoft.Json;
string json = new Newtonsoft.Json.JsonConvert.SerializeObject(new
{
jlpt = "5"
});
but it gives me an error saying that
SerializeObject does not exist.
However, when I click to check the reference I see it.
Can anyone point me to what I am doing wrong?
Upvotes: 1
Views: 2523
Reputation: 7352
Remove new
instance creation of Newtonsoft.Json.JsonConvert
, because SerializeObject
is a static method you don't need create a instance of the Newtonsoft.Json.JsonConvert
to use it
string json = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
jlpt = "5"
});
also if you add using Newtonsoft.Json;
to the program then you simply use like this
string json = JsonConvert.SerializeObject(new
{
jlpt = "5"
});
Upvotes: 6