2015-08-19 5 views
-2

Я пытаюсь dezilirze некоторых JSON в мой класс я использовал инструмент в http://json2csharp.com/ для преобразования запроса JSon из следующегоОпределение класса Json, является ли моя структура правильной для десериализации?

{ 
    "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 and 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 at 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 One 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" 
     } 
    ] 
} 

Но по какой-то причине я ударяя ошибку deubugger на процессе списка Thie. Мой GetMovieDetailAysnc работает, возвращая текст для строки json.

public async Task<List<MovieDetail>> GetMovieDetailsList(int movieId) 
{ 
     string jsonresult = await WCFRESTServiceCall("GET", "movie_details"); 
     var list = jsonresult.Deserialize<MovieDetails>(); 
     return list.movieDetaillist; 
} 

Но моя ошибка occourse на методе deserilize класс для деталей фильма заключается в следующем

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; } 
    } 

}

Мой вопрос: что может быть cuasing ошибку, я нахожусь в недоумении здесь как данные метод valid.My Deserlize как ниже

public static T Deserialize<T>(this string SerializedJSONString) 
{ 
     var stuff = JsonConvert.DeserializeObject<T>(SerializedJSONString); 
     return stuff; 
} 

Редактировать Заметки

Для Futher investaget это я получаю ошибку на

Дополнительная информация: Не удается десериализации объекта тока JSON (например, {"name": "value"}) в тип 'System.Collections.Generic.List`1 [popcornpk.DataModel.MovieDetails]', потому что для этого требуется массив JSON (например, [1,2,3]) для десериализации ,

+0

и почему отметьте удивительное, кто на этот раз! – rogue39nin

+2

Я не спустил вниз, но если вы отметите ошибку, было бы полезно дать подробную информацию о **, что это за ошибка, и ** точно **, в какой строке вы ее используете. –

+0

он просто тормозит на отладчик прилагается ошибка нет конкретной ошибки givin – rogue39nin

ответ

0

Я думаю, что проблема в том, что вы передаете неправильный тип для Deserialize метода - не MovieDetail, но MovieDetails (в случае, если я правильно понимаю, что ваша служба WCF возвращает один экземпляр) и использовать неправильный тип для общего Task результата. Так что просто попробуйте обновить метод GetMovieDetailsList(int movieId) с помощью следующего кода (включая подпись):

public async Task<MovieDetail> GetMovieDetailsList(int movieId) 
{ 
    string jsonresult = await WCFRESTServiceCall("GET", "movie_details"); 
    var details = jsonresult.Deserialize<MovieDetail>(); 
    return details; 
}