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
|
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);
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 TvCategoryArray Deserialize<TvCategoryArray>(string jsonString)
{
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TvCategoryArray));
//Console.WriteLine("TEST4"+ms);
var results = (TvCategoryArray)serializer.ReadObject(ms);
foreach(var test in results.Categories)
{
Console.WriteLine("TESTCACA"+test.id_rub_list);
}
return ((TvCategoryArray)results);
}
}
} |
Partager