10
Answers

How to will json data convert to object in c#?

Ken H

Ken H

10y
1.2k
1
hi all,
     Here is my code, attempts to convert the JSON data object, but failed to pass:
 
namespace ParseJson{
using System;
using Newtonsoft.Json;
class Program{
static void Main(string[] args){
string json = "{\"Verson\":\"2014\",\"Product\":[{\"ProductName\":\"Scottish cookies\",\"ProductionPlace\":{\"City\":\"Edinburgh\",\"State\":\"United Kingdom\"},\"Date\":\"14/10/2014\"}]\"}";
ProductInfo des = JsonConvert.DeserializeObject<ProductInfo>(json);
}
}
public class ProductInfo
{
public ProductInfo() { }
public string Verson { get; set; }
public string ProductName { get; set; }
public Address ProductionPlace { get; set; }
public DateTime Date { get; set; }
}
public class Address{
public Address() { }
public string City { get; set; }
public string State { get; set; }
}
}
 
Thanks. 
 
Answers (10)