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(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.

Ramesh MaruthiPosted Oct 14, 2014, 12:33 PM
Once try this
Ramesh MaruthiPosted Oct 15, 2014, 11:31 AM
Ken HPosted Oct 15, 2014, 11:27 AM
Ramesh MaruthiPosted Oct 15, 2014, 11:08 AM
http://james.newtonking.com/archive/2009/10/23/efficient-json-with-json-net-reducing-serialized-json-size
Ramesh MaruthiPosted Oct 15, 2014, 10:56 AM
you can ignore the datamemeber which you doesn't want to display ([IgnoreDataMember]) see in the above example i ignored Verson, hope this helps you :)
VulpesPosted Oct 15, 2014, 10:45 AM
string[] products = this.Product.Select(p => p.ToString()).ToArray();
I can only think that you don't have this 'using' directive in your version of the program:
using System.Linq;
Ken HPosted Oct 15, 2014, 10:41 AM
If I just want to get specific data, then what should be done?
For example, just below a bold font data(Other ignore):
[
"PropertyName1":"Value1",
"PropertyName2":"Value2",
"PropertyName3":"Value3",
"Product":[{
"ProductName":"Scottish cookies",
"ProductionPlace":{
"City":"Edinburgh",
"State":"United Kingdom"
}
}],
"Date":"14/10/2014"
]
Thanks.
Ken HPosted Oct 15, 2014, 10:20 AM
Ken HPosted Oct 15, 2014, 10:12 AM
An error occurred: does not contain a "Select" is defined.
VulpesPosted Oct 14, 2014, 4:20 PM
The output is: