Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to convert json data with multiple arrays to list in c# mvc

json data :-

[
{
"resultList": [
{
"channelType": "",
"duration": "2:29:30",
"episodeno": 0,
"genre": "Drama",
"genreList": [
"Drama"
],
"genres": [
{
"personName": "Drama"
}
],
"id": 1204,
"language": "Hindi",
"name": "The Great Target",
"productId": 1204,
"productMasterId": 1203,
"productMasterName": "The Great Target",
"productName": "The Great Target",
"productTypeId": 1,
"productTypeName": "Movie",
"rating": 3,
"releaseyear": "2005",
"showGoodName": "Movies ",
"views": 8333
},
{
"channelType": "",
"duration": "2:30:30",
"episodeno": 0,
"genre": "Romance",
"genreList": [
"Romance"
],
"genres": [
{
"personName": "Romance"
}
],
"id": 1144,
"language": "Hindi",
"name": "Mere Sapnon Ki Rani",
"productId": 1144,
"productMasterId": 1143,
"productMasterName": "Mere Sapnon Ki Rani",
"productName": "Mere Sapnon Ki Rani",
"productTypeId": 1,
"productTypeName": "Movie",
"rating": 3,
"releaseyear": "1997",
"showGoodName": "Movies ",
"views": 6482
},
{
"channelType": "",
"duration": "2:34:07",
"episodeno": 0,
"genre": "Drama",
"genreList": [
"Drama"
],
"genres": [
{
"personName": "Drama"
}
],
"id": 1520,
"language": "Telugu",
"name": "Satyameva Jayathe",
"productId": 1520,
"productMasterId": 1519,
"productMasterName": "Satyameva Jayathe",
"productName": "Satyameva Jayathe",
"productTypeId": 1,
"productTypeName": "Movie",
"rating": 3,
"releaseyear": "2004",
"showGoodName": "Movies ",
"views": 9910
}
],
"resultSize": 1171,
"pageIndex": "1"
}
]

What I have tried:

public class Class3
{

public List<listwrapper_main> ResultList_Main { get; set; }

public class ListWrapper_Main
{
public List<listwrapper> ResultList { get; set; }

public string resultSize { get; set; }
public string pageIndex { get; set; }
}

public class ListWrapper
{
public string channelType { get; set; }
public string duration { get; set; }
public int episodeno { get; set; }
public string genre { get; set; }
public string[] genreList { get; set; }
public List<genres_cls> genres { get; set; }
public int id { get; set; }
public string imageUrl { get; set; }
//public string imageurl { get; set; }
public string language { get; set; }
public string name { get; set; }
public int productId { get; set; }
public int productMasterId { get; set; }
public string productMasterName { get; set; }
public string productName { get; set; }
public int productTypeId { get; set; }
public string productTypeName { get; set; }
public decimal rating { get; set; }
public string releaseYear { get; set; }
//public string releaseyear { get; set; }
public string showGoodName { get; set; }
public string views { get; set; }
}
public class genres_cls
{
public string personName { get; set; }
}

}
Posted
Updated 29-Jul-16 2:45am

1 solution

Pasting your JSON into this tool[^] produces:
C#
public class Genre
{
    public string personName { get; set; }
}

public class ResultList
{
    public string channelType { get; set; }
    public string duration { get; set; }
    public int episodeno { get; set; }
    public string genre { get; set; }
    public List<string> genreList { get; set; }
    public List<Genre> genres { get; set; }
    public int id { get; set; }
    public string language { get; set; }
    public string name { get; set; }
    public int productId { get; set; }
    public int productMasterId { get; set; }
    public string productMasterName { get; set; }
    public string productName { get; set; }
    public int productTypeId { get; set; }
    public string productTypeName { get; set; }
    public int rating { get; set; }
    public string releaseyear { get; set; }
    public string showGoodName { get; set; }
    public int views { get; set; }
}

public class RootObject
{
    public List<ResultList> resultList { get; set; }
    public int resultSize { get; set; }
    public string pageIndex { get; set; }
}

If the extra [ at the beginning of your JSON is a typo, then you would use something like this:
C#
RootObject result = JsonConvert.DeserializeObject<RootObject>(yourJsonString);

If the missing ] at the end of your JSON is a typo, then you would use something like this:
C#
List<RootObject> result = JsonConvert.DeserializeObject<List<RootObject>>(yourJsonString);

(This assumes you're using JSON.NET[^])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900