I'm using
var myResponse = new Response(myDictionary);
string response = JsonConvert.SerializeObject(myResponse);
where
internal class Response
{
public Response (Dictionary<string, string> myDict)
{
MyDict = myDict;
}
public Dictionary<string, string> MyDict { get; private set; }
}
I'm getting:
{
"MyDict":
{
"key" : "value",
"key2" : "value2"
}
}
what I want to get is:
{
"key" : "value",
"key2" : "value2"
}
`
is that possible with Newtonsoft.Json?
You're serializing the entire object. if you just want the output you specified then just serialize the dictionary:
string response = JsonConvert.SerializeObject(myResponse.MyDict);
this will output:
{"key":"value","key2":"value2"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With