0

I am working on a C# project however I am in need of some advice.

I am presently posting to my site:

{Tags : 'App', Limit : '10' }

And it can cast this to the following class

[Serializable]
public class MiloFilter
{
    public string Tags { get; set; }
    public string Limit { get; set; }
}

However what I am wanting to accomplish is that I would like to post my JSON like this:

{ MiloFilter : {Tags : 'SomeTag', Limit : '1' }}

However when I try and parse it using the following method it fails.

var js = new System.Web.Script.Serialization.JavaScriptSerializer();
var miloFilter = js.Deserialize<MiloFilter>(bodyText);

How can I acomplish this?

0

1 Answer 1

1

You can easily create your own serializer

var car = new Car() { Name = "Ford", Owner = "John Smith" };
string json = Serialize(car);

string Serialize<T>(T o)
{
    var attr = o.GetType().GetCustomAttribute(typeof(JsonObjectAttribute)) as JsonObjectAttribute;

    var jv = JValue.FromObject(o);

    return new JObject(new JProperty(attr.Title, jv)).ToString();
}

source

Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.