Deserialisation Json vers object
Bonsoir,
L'objet que me renvois
serializer.ReadObject est un objet vide.
Dés que j'essaye d'y accéder il me renvoie un "System.NullReferenceException"
Ci dessous la chaine json renvoyé (testé elle est bien stocké et renvoyé a la fonction Deserialize).
En dessous ce trouve le code concerné.
Merci d'avance.
Code:
[{"id_rub_list":"151","rub_en":"1channel","rub_fr":"1channel","rub_ar":"","rub_th":"1channel","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1332495395.","thumbnail":"..\/stb\/item\/\/tv_live1\/1332495395.thumbnail.","summary_en":"1channel","summary_fr":"1channel","summary_ar":"","summary_th":"1channel","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"23","rub_en":"ABU DHABI HD","rub_fr":"ABU DHABI HD","rub_ar":"ABU DHABI HD","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"1","rub_en":"Basic","rub_fr":"Basique","rub_ar":"Basic AR","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"22","rub_en":"Catchup Tv","rub_fr":"Catchup Tv","rub_ar":"Catchup Tv","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"191","rub_en":"Demo","rub_fr":"Demo","rub_ar":"","rub_th":"Demo","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1345649499.","thumbnail":"..\/stb\/item\/\/tv_live1\/1345649499.thumbnail.","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"12","rub_en":"Family09","rub_fr":"Family09","rub_ar":"Family09","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"131","rub_en":"live test's and go","rub_fr":"live test's and go","rub_ar":"live test's and go","rub_th":"","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1325872959.","thumbnail":"..\/stb\/item\/\/tv_live1\/1325872959.thumbnail.","summary_en":"live test's and go","summary_fr":"live test's and go","summary_ar":"live test's and go","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"161","rub_en":"Mobile Movies","rub_fr":"Mobile Movies","rub_ar":"","rub_th":"Mobile Movies","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1335513968.","thumbnail":"..\/stb\/item\/\/tv_live1\/1335513968.thumbnail.","summary_en":"Mobile Movies","summary_fr":"Mobile Movies","summary_ar":"","summary_th":"Mobile Movies","summary_jp":"","trailer":"Mobile Movies","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"11","rub_en":"Movies Plus","rub_fr":"Base","rub_ar":"Movies Plus","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"82","rub_en":"OSN Family Plus","rub_fr":"OSN Family Plus","rub_ar":"OSN Family Plus","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"21","rub_en":"OSN on Demand","rub_fr":"OSN on Demand","rub_ar":"OSN on Demand","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"42","rub_en":"OSN Platinum Extra HD","rub_fr":"OSN Platinum Extra HD","rub_ar":"OSN Platinum Extra HD","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"62","rub_en":"OSN Premier Plus HD","rub_fr":"OSN Premier Plus HD","rub_ar":"OSN Premier Plus HD","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"181","rub_en":"OTT Catch-up","rub_fr":"OTT Catch-up","rub_ar":"","rub_th":"OTT Catch-up","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1338562618.","thumbnail":"..\/stb\/item\/\/tv_live1\/1338562618.thumbnail.","summary_en":"OTT Catch-up","summary_fr":"OTT Catch-up","summary_ar":"","summary_th":"OTT Catch-up","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"171","rub_en":"OTT Live TV","rub_fr":"OTT Live TV","rub_ar":"","rub_th":"OTT Live TV","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1338562560.","thumbnail":"..\/stb\/item\/\/tv_live1\/1338562560.thumbnail.","summary_en":"OTT Live TV","summary_fr":"OTT Live TV","summary_ar":"","summary_th":"OTT Live TV","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"16","rub_en":"Pehla Basic","rub_fr":"Pehla Basic","rub_ar":"Pehla Basic","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"3","rub_en":"Premier Plus2","rub_fr":"ART","rub_ar":"Premier Plus","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"18","rub_en":"Sport Packages","rub_fr":"Primary Packages","rub_ar":"Sport Packages","rub_th":"","rub_jp":"","picture":"","thumbnail":"","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""},{"id_rub_list":"20","rub_en":"Test en","rub_fr":"Test fr","rub_ar":"Test ar","rub_th":"","rub_jp":"","picture":"..\/stb\/item\/\/tv_live1\/1328260736.png","thumbnail":"..\/stb\/item\/\/tv_live1\/1328260736.thumbnail.png","summary_en":"","summary_fr":"","summary_ar":"","summary_th":"","summary_jp":"","trailer":"","offer_start":"0000-00-00","offer_stop":"0000-00-00","offer_length":"0","price":"0","usage":""}]
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public class TvCategory
{
public class TvCategoryEntry
{
public string id_rub_list;
public string rub_en;
public string rub_fr;
public string rub_ar;
public string rub_th;
public string rub_jp;
public string picture;
public string thumbnail;
public string summary_en;
public string summary_fr;
public string summary_ar;
public string summary_th;
public string summary_jp;
public string trailer;
public string offer_start;
public string offer_stop;
public string offer_length;
public string price;
public string usage;
}
public class TvCategoryArray
{
public IList<TvCategoryEntry> Categories{ get; set; }
}
public TvCategory ()
{
}
public void TVcategoryRequest()
{
string url = "http://127.0.0.1/mobileApp/php/channelCategories.php";
var request = WebRequest.Create(url);
//request.Timeout = 100000;
string text;
var response = (HttpWebResponse) request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
Console.WriteLine("text2"+text);
}
TvCategoryArray Cat = (TvCategoryArray)Deserialize<TvCategoryArray>(text);
//Console.WriteLine("test3"+ Cat.Categories);
}
public static TvCategory.TvCategoryArray Deserialize<TvCategoryArray>(string jsonString)
{
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TvCategory.TvCategoryArray));
//Console.WriteLine("TEST4"+ms);
var results = (TvCategory.TvCategoryArray)serializer.ReadObject(ms);
foreach(var test in results.Categories)
{
//Console.WriteLine("TESTCACA"+test.id_rub_list);
}
return ((TvCategory.TvCategoryArray)results);
}
}
} |