質問

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?

}
役に立ちましたか?

解決

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; }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top