How do i serialize multiple c# classes to one json string using . Be able to make the variables in the json data hold values that can change
string outputJSON = JsonConvert.SerializeObject();
i have the following classes
public class Rootobject { public string Number { get; set; } public string RequestedDeviceType { get; set; } public string DeliveryMethod { get; set; } public Customer Customer { get; set; } public Vehicle Vehicle { get; set; } } public class Customer { public Contacts Contacts { get; set; } public string Name { get; set; } public string Number { get; set; } public bool OverrideData { get; set; } } public class Contacts { public string FirstName { get; set; } public string Name { get; set; } public string Email { get; set; } public string City { get; set; } public string Address { get; set; } public string MobilePhone { get; set; } } public class Vehicle { public string VIN { get; set; } public string MakeModelCode { get; set; } public string LicensePlate { get; set; } public string Make { get; set; } public string Model { get; set; } public int YearOfInitialRegistration { get; set; } public string MotorType { get; set; } public bool OverrideData { get; set; } } } They must serialize to the following structure of json structure and i must be able to capture user input and set the values into json file
{ "Number": "xTest", "RequestedDeviceType": "XXXX", "DeliveryMethod": "XXXX", "Customer": { "Contacts": { "FirstName": "John", "Name": "Doe", "Email": "[email protected]", "City": "Harare", "Address": "XXXXX", "MobilePhone": "00000000" }, "Name": "Peter Chaneta", "Number": "4567865678", "OverrideData": true }, "Vehicle": { "VIN": "weryts55444554", "MakeModelCode": "34010", "LicensePlate": "SS 100 GP", "Make": "RANGE ROVER", "Model": "SPORT", "YearOfInitialRegistration": 2016, "MotorType": "Petrol", "OverrideData": true } }
string output = JsonConvert.SerializeObject(yourobject);does that?!? The json representation reflects your class composition, that's the job