c# - Json class definition, is my structure correct for deserialization? -
i trying dezilirze json class used tool @ http://json2csharp.com/ transform json request following
{ "movie_details": { "id": "1", "name": "movie 1", "description": "movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n\r\nmovie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n\r\nmovie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n\r\nmovie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n\r\nmovie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n\r\nmovie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1movie 1\r\n", "image": "http://popcorn.pk/img/movie/harley3.jpg", "secondry_images": "movie/jellyfish.jpg,movie/koala.jpg,movie/jellyfish.jpg", "actor": "anandan", "actoress": "anandan", "director": "anandan", "music_director": "anandan", "release_date": "march 18, 2015", "tags": "movie 1,movie 1 ", "age_restriction": "14", "box_office": "36985214", "official_site": "http://google.com", "duration": "1.50 hr", "writers": "anandan", "imdb": 8, "status": "1", "language": "tamil", "created": "2015-03-11 05:11:31", "modified": "2015-03-25 10:12:39", "movie_category_id": "action", "slug": "movie 1 ", "movie_show_time_id": "0", "theatre_movie_screen_id": "0", "videous": "", "videos": "", "comming_soon": "0", "avg": 0, "movie_details_url": "http://popcorn.pk/launch/movies/view/1" }, "fetch_timing": [ { "id": "23", "theater_name": "super cinema - royal palm", "address": "royal palm golf , country club, 52 canal bank road, lahore", "show_times": [ "4:00 pm" ], "screen_id": "28", "title": "standard screen" }, { "id": "24", "theater_name": "sozo world cinema", "address": "fortress stadium, lahore - cantt, lahore, pakistan", "show_times": [ "2:30 pm", "7:30 pm" ], "screen_id": "29", "title": "standard screen" }, { "id": "25", "theater_name": "atrium cinema", "address": "3rd floor, atrium mall, 249 staff lines, zaibunnisa street, saddar. karachi, pakistan", "show_times": [ "5:15 pm", "11:30 am" ], "screen_id": "30", "title": "standard screen" }, { "id": "26", "theater_name": "universe cineplex", "address": "55-c, khayaban-e-muslim, muslim commercial area phase 6, d.h.a. karachi, pakistan", "show_times": [ "3:30 pm", "9:30 pm", "6:30 pm" ], "screen_id": "31", "title": "standard screen" }, { "id": "27", "theater_name": "cinepax - ocean mall", "address": "cinepax, ocean tower, 2 sword, clifton, karachi", "show_times": [ "5:45 pm" ], "screen_id": "32", "title": "standard screen" }, { "id": "28", "theater_name": "cinepax - city auditorium", "address": "opposite meezan bank regional office @ ayesha manzil, fb area block 14,karachi,pakistan", "show_times": [ "3:00 pm" ], "screen_id": "33", "title": "standard screen" }, { "id": "29", "theater_name": "nueplex", "address": "the place, khayaban e shaheen phase 8, d.h.a", "show_times": [ "6:15 pm", "3:10 pm" ], "screen_id": "34", "title": "standard screen" }, { "id": "30", "theater_name": "centaurus cineplex", "address": "centaurus mall, 1 jinnah avenue, 4th floor centaurus, f-8 islamabad", "show_times": [ "8:00 pm" ], "screen_id": "35", "title": "standard screen" }, { "id": "31", "theater_name": "the arena", "address": "the arena, rawapindi, pakistan", "show_times": [ "8:30 pm", "5:45 pm" ], "screen_id": "36", "title": "standard screen" }, { "id": "32", "theater_name": "cine moosh", "address": "house no. a/18, unit no.3, main autobhan road, latifabad, hyderabad", "show_times": [ "3:00 pm" ], "screen_id": "37", "title": "standard screen" }, { "id": "33", "theater_name": "cinegold plex", "address": "main boulevard, garden city, between phase 7 & 8, expressway, rawalpindi 46000", "show_times": [ "7:45 pm" ], "screen_id": "38", "title": "standard screen" }, { "id": "34", "theater_name": "cinepax jinnah park", "address": "cinepax jinnah park kachehri road, rawalpindi 00e220ac201c pakistan", "show_times": [ "12:00 pm", "8:00 pm" ], "screen_id": "39", "title": "standard screen" }, { "id": "35", "theater_name": "cinepax hotel one", "address": "hotel 1 99/c, peoples colony (near d ground) faisalabad", "show_times": [ "3:00 pm" ], "screen_id": "40", "title": "standard screen" }, { "id": "36", "theater_name": "super cinema", "address": "vogue tower, mm alam road, lahore", "show_times": [ "2:15 pm" ], "screen_id": "41", "title": "standard screen" }, { "id": "38", "theater_name": "cine star", "address": "plot #13,2 civic center township lahore", "show_times": [ "7:15 pm" ], "screen_id": "43", "title": "standard screen" }, { "id": "39", "theater_name": "taj cinema", "address": "plot #13,2 civic center township lahore", "show_times": [ "2:00 pm", "10:00 pm" ], "screen_id": "44", "title": "standard screen" }, { "id": "40", "theater_name": "cinestar imax", "address": "plot #13,2 civic center township lahore", "show_times": [ "2:00 pm", "7:30 pm" ], "screen_id": "45", "title": "standard screen" }, { "id": "41", "theater_name": "taj mahal multiplex", "address": "taj mahal multiplex cinemas, railway road, faisalabad-38000", "show_times": [ "4:00 pm", "10:00 pm", "7:00 pm" ], "screen_id": "46", "title": "standard screen" }, { "id": "42", "theater_name": "the arena orchard", "address": "phase 1 baharia orchard raiwind road, lahore, pakistan", "show_times": [ "11:15 pm", "11:00 am" ], "screen_id": "47", "title": "standard screen" }, { "id": "44", "theater_name": "dha cinema", "address": "305-r block, d.h.a, lahore pakistan", "show_times": [ "5:00 pm", "10:30 pm" ], "screen_id": "49", "title": "standard screen" }, { "id": "45", "theater_name": "cinepax fortress", "address": "2nd floor, fortress square shopping mall, lahore - pakistan", "show_times": [ "8:15 pm", "10:45 pm", "2:30 pm" ], "screen_id": "50", "title": "standard screen" }, { "id": "47", "theater_name": "imperial cinemas", "address": "imperial garden homes, lahore, pakistan", "show_times": [ "2:30 pm" ], "screen_id": "52", "title": "standard screen" }, { "id": "48", "theater_name": "cinepax gujranwala", "address": "prince cinepax main g t road, gujranwala - pakistan", "show_times": [ "8:45 pm", "5:45 pm", "6:00 pm" ], "screen_id": "53", "title": "standard screen" }, { "id": "49", "theater_name": "super cinema - gujrat", "address": "super cinema gujrat, gt road, gujrat", "show_times": [ "1:00 pm", "10:00 pm", "7:00 pm" ], "screen_id": "54", "title": "standard screen" }, { "id": "50", "theater_name": "paf cinema", "address": "sarfaraz rafiqui road, lahore, pakistan", "show_times": [ "3:00 pm", "11:00 pm", "2:00 am" ], "screen_id": "55", "title": "standard screen" }, { "id": "51", "theater_name": "capri cinema", "address": "gazdarabad, karachi, pakistan, karachi, pakistan", "show_times": [ "6:00 pm" ], "screen_id": "56", "title": "standard screen" } ] }
but reason hitting deubugger error on process of thie list. getmoviedetailaysnc working bringing text fine json string.
public async task<list<moviedetail>> getmoviedetailslist(int movieid) { string jsonresult = await wcfrestservicecall("get", "movie_details"); var list = jsonresult.deserialize<moviedetails>(); return list.moviedetaillist; }
but error occourse on deserilize method class movie details follows
public class moviedetails { public string id { get; set; } public string name { get; set; } public string description { get; set; } public string image { get; set; } public string secondry_images { get; set; } public string actor { get; set; } public string actoress { get; set; } public string director { get; set; } public string music_director { get; set; } public string release_date { get; set; } public string tags { get; set; } public string age_restriction { get; set; } public string box_office { get; set; } public string official_site { get; set; } public string duration { get; set; } public string writers { get; set; } public int imdb { get; set; } public string status { get; set; } public string language { get; set; } public string created { get; set; } public string modified { get; set; } public string movie_category_id { get; set; } public string slug { get; set; } public string movie_show_time_id { get; set; } public string theatre_movie_screen_id { get; set; } public string videous { get; set; } public string videos { get; set; } public string comming_soon { get; set; } public int avg { get; set; } public string movie_details_url { get; set; } } public class fetchtiming { public string id { get; set; } public string theater_name { get; set; } public string address { get; set; } public list<string> show_times { get; set; } public string screen_id { get; set; } public string title { get; set; } } public class moviedetail { public moviedetails movie_details { get; set; } public list<fetchtiming> fetch_timing { get; set; } }
}
my question cuasing error @ loss here data valid.my deserlize method below
public static t deserialize<t>(this string serializedjsonstring) { var stuff = jsonconvert.deserializeobject<t>(serializedjsonstring); return stuff; }
edit notes
to futher investaget getting error on
additional information: cannot deserialize current json object (e.g. {"name":"value"}) type 'system.collections.generic.list`1[popcornpk.datamodel.moviedetails]' because type requires json array (e.g. [1,2,3]) deserialize correctly.
i think problem pass wrong type deserialize
method – not moviedetail
, moviedetails
(in case understand wcf service returns single instance) , use wrong type generic task
result. try updating getmoviedetailslist(int movieid)
method following code (including signature):
public async task<moviedetail> getmoviedetailslist(int movieid) { string jsonresult = await wcfrestservicecall("get", "movie_details"); var details = jsonresult.deserialize<moviedetail>(); return details; }
Comments
Post a Comment