Ken H

Ken H

  • NA
  • 646
  • 354k

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

Oct 14 2014 11:40 AM
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)