0

I want to create JSON with nested arrays and objects like this:

{"orderId": "AF34235", 
 "recipients": [{"name": "Jane Doe", "address": "123 Main"},
                {"name": "Bob Doe", "address": "456 Broad"}],
 "sender": {"id": 123, "address": "789 Spruce"}
}

Is this possible with DataContractJsonSerializer? If so, what should my entity look like?

[DataContract]
class Order
{
    [DataMember(Name = "orderId")]
    public string OrderId { get; set; }

    // what next?

}

1 Answer 1

1

what should my entity look like?

See this site http://json2csharp.com/

public class Recipient
{
    public string name { get; set; }
    public string address { get; set; }
}

public class Sender
{
    public int id { get; set; }
    public string address { get; set; }
}

public class RootObject
{
    public string orderId { get; set; }
    public List<Recipient> recipients { get; set; }
    public Sender sender { get; set; }
}
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.