I need to get:
public class Package
{
public Package()
{
name = "";
type = new List<Dictionary<string, string>>();
}
public string name { get; set; }
public List<Dictionary<string, string>> type { get; set; }
}
into:
{
"name":"package_name",
"type":
{
"http://random.url.as.key":"random/value"
}
}
with:
Package package = new Package();
package.name = "package_name";
package.type.Add(new Dictionary<string, string>() { { "http://random.url.as.key", "random/value" } });
I get:
{
"name":"package_name",
"type":
[
[
{
"Key":"http://random.url.as.key",
"Value":"random/value"
}
]
]
}
while, with:
var package = new
{
name = "package_name",
type = new
{
http_random_url_as_key = "random/value"
}
};
I get:
{
"name":"package_name",
"type":
{
"http_random_url_as_key":"random/value"
}
}
I can't get the obsure http://random.url.as.key that I need. I have tried using JavaScriptSerializer, DataContractJsonSerializer, and Custom Convertor for Json.NET, all with limited success/shortcomings.
There must be a better way/something I'm overlooking to get a simple JSON Object over the wire!
See Question&Answers more detail:os