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 MaruthiRank #937 · 2.2K reputationPosted Oct 14, 2014, 8:33 AM EDT
Once try this
VulpesRank #55 · 29.2K reputationPosted Oct 14, 2014, 12:20 PM EDT
The output is:
VulpesRank #55 · 29.2K reputationPosted Oct 15, 2014, 6:45 AM EDT
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 HRank #2,315 · 610 reputationPosted Oct 15, 2014, 7:27 AM EDT
Ken HRank #2,315 · 610 reputationPosted Oct 15, 2014, 6:12 AM EDT
An error occurred: does not contain a "Select" is defined.
Ken HRank #2,315 · 610 reputationPosted Oct 15, 2014, 6:20 AM EDT
Ken HRank #2,315 · 610 reputationPosted Oct 15, 2014, 6:41 AM EDT
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.
Ramesh MaruthiRank #937 · 2.2K reputationPosted Oct 15, 2014, 6:56 AM EDT
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 :)
Ramesh MaruthiRank #937 · 2.2K reputationPosted Oct 15, 2014, 7:08 AM EDT
http://james.newtonking.com/archive/2009/10/23/efficient-json-with-json-net-reducing-serialized-json-size
Ramesh MaruthiRank #937 · 2.2K reputationPosted Oct 15, 2014, 7:31 AM EDT