I am relatively new to c# programming. I need help for these problems that i have been facing in assignment.
{
"Non_Portable": [{
"NameOfGamingEquipments": "Playstation 4",
"ResourceId": 1,
"RentalPrice": 200,
"DeliveryMode": "Hand Carry",
"quantityOfCables": 2,
"TypeOfCable": "Micro USB for controller and HDMI for display",
"Accessories": "2 wireless Dualshock 4 controllers"
}, {
"NameOfGamingEquipments": "Xbox One",
"ResourceId": 2,
"RentalPrice": 200,
"DeliveryMode": " Hand Carry",
"quantityOfCables": 2,
"TypeOfCable": " Micro USB cable for controller and HDMI cable for display",
"Accessories": "batteries for controller"
}, {
"NameOfGamingEquipments": "Playstation 3",
"ResourceId": 3,
"RentalPrice": 120,
"DeliveryMode": "delivery via deliveryman",
"quantityOfCables": 1,
"TypeOfCable": "HDMI cable for display",
"Accessories": "Wireless dualshock 3 controller for Playstation 3"
}
],
"Portable": [{
"NameOfGamingEquipments": "Nintendo 3DS",
"ResourceId": 4,
"RentalPrice": 50,
"DeliveryMode": "Hand carry",
"sizeOfScreen": "Top: 4.88 Bottom: 4.18",
"quantityOfCartridges": 1,
"CartridgeName": "Super Mario",
"touchScreenFunction": true
}, {
"NameOfGamingEquipments": "Sony Playstation Vita",
"ResourceId": 5,
"RentalPrice": 70,
"DeliveryMode": "Self Pick Up",
"sizeOfScreen": "5 inches",
"quantityOfCartridges": 2,
"CartridgeName": "Powerpuff Girls and GTA ",
"touchScreenFunction": true
}, {
"NameOfGamingEquipments": "Nintendo 3DS XL",
"ResourceId": 6,
"RentalPrice": 40,
"DeliveryMode": "Self Pick Up",
"sizeOfScreen": "Top: 4.88 bottom: 4.18 ",
"quantityOfCartridges": 1,
"CartridgeName": "Ridge Racer",
"touchScreenFunction": true
}]
}
The above is my JSON File. The assignment requires me to load data from text file hence I am using streamreader to read the data from json.
public class Resource {
public static List < UserAccount > UserAccounts {
get;
set;
} //container for useraccounts
public List < Non_Portable > Non_PortableEquip {
get;
set;
}
public List < Portable > PortableEquip {
get;
set;
}
public List < Booking > Bookings {
get;
set;
}
public List < BookingDetail > BookingDetails {
get;
set;
}
public abstract class GamingEquipment {
public string NameOfGamingEquipments
{
get;
set;
}
public int ResourceId
{
get;
set;
}
public double RentalPrice {
get;
set;
}
public string DeliveryMode
{
get;
set;
}
}
public class Non_Portable: GamingEquipment {
public int quantityOfCables
{
get;
set;
}
public string TypeOfCable
{
get;
set;
}
public string Accessories
{
get;
set;
}
}
public class Portable: GamingEquipment {
public string sizeOfScreen
{
get;
set;
}
public double quantityOfCartridges
{
get;
set;
}
public string CartridgeName
{
get;
set;
}
public bool touchScreenFunction
{
get;
set;
}
}
public class UserAccount {
private string userName;
private string passWord;
private string name;
private string email;
private int cardNum;
private DateTime expiryDate;
private string paymentType;
private string address;
public string Username {
set {
userName = value;
}
get {
return userName;
}
}
public string Password {
set {
passWord = value;
}
get {
return passWord;
}
}
public string Name {
set {
name = value;
}
get {
return name;
}
}
public string Email {
set {
email = value;
}
get {
return email;
}
}
public int CardNum {
set {
cardNum = value;
}
get {
return cardNum;
}
}
public DateTime ExpiryDate {
set {
expiryDate = value;
}
get {
return expiryDate;
}
}
public string PaymentType {
set {
paymentType = value;
}
get {
return paymentType;
}
}
public string Address {
set {
address = value;
}
get {
return address;
}
}
}
Now then I have read the json
data from the file, How do I deserialize json data and have them collected to their respective lists ? I am working in windows form application. Thanks for everyone's help and advice in advance.
Reading json data from file
using(StreamReader file = File.OpenText(@ "Data.JSON")) {}