I searched for an answer, found something similar but not exact my case.
So, I have a URL that returns JSON when i request. Json is like this:
{"12458":{"id":"12458","name":"Deccal","short":"<p>H\u0259yat\u0131n\u0131n s\u0131x\u0131nt\u0131l\u0131 vaxtlar\u0131n\u0131 ya\u015fayan Duygu, x\u0259st\u0259xanadan
ç\u0131xd\u0131qdan sonra t\u0259sadüf\u0259n Nurdan ad\u0131nda...<\/p>","full":"<p>H\u0259yat\u0131n\u0131n s\u0131x\u0131nt\u0131l\u0131 vaxtlar\u0131n\u0131 ya\u015fayan
Duygu, x\u0259st\u0259xanadan ç\u0131xd\u0131qdan sonra t\u0259sadüf\u0259n Nurdan ad\u0131nda, sirli v\u0259 o q\u0259d\u0259r d\u0259 varl\u0131 qad\u0131nla tan\u0131\u015f
olur. Nurdan\u0131n maddi v\u0259 m\u0259n\u0259vi köm\u0259yini, ehtiyac\u0131 oldu\u011fu üçün q\u0259bul ed\u0259n Duy\u011funun h\u0259yat\u0131 inan\u0131lmaz
d\u0259yi\u015fir. \u018fn yax\u0131n dostu Asl\u0131 da bu v\u0259ziyy\u0259td\u0259n raz\u0131d\u0131r. Amma sonradan Duygunun yerl\u0259\u015fdiyi q\u0259rib evd\u0259 q\u0259rib\u0259
hadis\u0259l\u0259r ba\u015f verm\u0259y\u0259 ba\u015flay\u0131r. Duygu haradan g\u0259ldiyi bilinm\u0259y\u0259n s\u0259sl\u0259r e\u015fidir v\u0259 kölg\u0259l\u0259r
içind\u0259 psixologiyas\u0131 daha da pisl\u0259\u015fir. Dig\u0259r t\u0259r\u0259fd\u0259n d\u0259, x\u0259st\u0259xanada iki q\u0131z\u0131 da yeni x\u0259b\u0259rl\u0259r
gözl\u0259yir.<\/p>\n<p>Rejissor: Özgür Bakar <\/p>\n<p>Ssenarist: Alper K\u0131v\u0131lc\u0131m, Özgür
Bakar <\/p>","dates":[{"place":"\"Nizami\" kinoteatr\u0131","dates":"20 avqust - 10 sentyabr","prices":["14:45 : 4 AZN","18:50 : 7 AZN"]}]},"11949":{"id":"11949","name":"Kocan kadar
konus","short":"<p>Filmd\u0259 h\u0259yat\u0131n\u0131n do\u011fru insan\u0131n\u0131 tapa bilm\u0259y\u0259n bir qad\u0131n\u0131n hekay\u0259sind\u0259n b\u0259hs
edilir<\/p>","full":"<p>\u015e\u0259bn\u0259m Burcuo\u011flunun eyni adl\u0131 roman\u0131 \u0259sas\u0131nda ç\u0259kilmi\u015f filmd\u0259 h\u0259yat\u0131n\u0131n do\u011fru
insan\u0131n\u0131 tapa bilm\u0259y\u0259n bir qad\u0131n\u0131n hekay\u0259sind\u0259n b\u0259hs edilir.<\/p>\n<p>Rollarda: Ejqi Mola, Murad
Y\u0131ld\u0131r\u0131m<\/p>","dates":[{"place":"28 Cinema","dates":"15 avqust - 11 sentyabr","prices":["15:40 : 5 AZN"]}]},...
There are lots of objects with structure like:
{
string id,
string name,
string short,
string full,
string dates{
string place,
string dates,
string[] prices
}
}.
My Class
[DataContract]
public class FilmList
{
[DataMember]
public List<Film> films { get; set; }
public class Film
{
[DataMember(Name = "id")]
public string id { get; set; }
[DataMember(Name = "name")]
public string name { get; set; }
[DataMember(Name = "short")]
public string s { get; set; }
[DataMember(Name = "full")]
public string full { get; set; }
[DataMember(Name = "dates")]
public Dates dates { get; set; }
public class Dates
{
[DataMember(Name = "place")]
public string place { get; set; }
[DataMember(Name = "dates")]
public string dates { get; set; }
[DataMember(Name = "prices")]
public List<string> prices { get; set; }
}
}
}
Code
DataContractJsonSerializer j = new DataContractJsonSerializer(typeof(FilmList));
//Film f = null;
JavaScriptSerializer ser = new JavaScriptSerializer();
using (var s = resp.GetResponseStream())//var sr = new StreamReader(resp.GetResponseStream()))
{
//var s = ser.Serialize(sr.ReadToEnd());
//f = (Film)j.ReadObject(s);
FilmList f = (FilmList)j.ReadObject(s);//ser.Deserialize<FilmList>(sr.ReadToEnd());
//var json = ser.Deserialize<FilmList>(sr.ReadToEnd());
}
resp.Close();
I tried both DataContractJsonSerializer and JavaScriptSerializer, and both return me null. I think it might be because JSON doesn't have a header element - just list of objects, but i'm not sure.