如何将多个数组的json数据转换为C#MVC中的列表 [英] How to convert json data with multiple arrays to list in C# MVC

查看:118
本文介绍了如何将多个数组的json数据转换为C#MVC中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将多个数组的json数据转换为c#mvc列表



json数据: -



[

{

resultList:[

{

channelType:,

持续时间:2:29:30,

episodeno:0,

流派:戏剧,

genreList:[

剧情

],

流派:[

{

personName:戏剧

}

],

id :1204,

语言:印地语,

名称:伟大的目标,

productId:1204 ,

productMasterId:1203,

productMasterName:伟大的目标,

productName:伟大的目标,

productTypeId:1,

productTypeName:电影,

评级:3,

releaseyear:2005,

showGoodName:电影,

views:8333

},

{

channelType:,

持续时间:2:30:30,

episodeno:0,

流派:浪漫,

genreList:[

浪漫

],

流派:[

{

personName:浪漫

}

],

id:1144,

语言:印地语,

name:仅仅是Sapnon Ki Rani,

productId:1144,

productMasterId:1143,

productMasterName :仅仅是Sapnon Ki Rani,

productName:仅仅是Sapnon Ki Rani,

productTypeId:1,

productTypeName:电影,

评级:3,

easeyear:1997,

showGoodName:电影,

观看次数::6482

},

{

channelType:,

持续时间:2:34:07,

episodeno:0,

genre:戏剧,

genreList:[

剧情

],

流派:[

{

personName:戏剧

}

],

id:1520,

语言:泰卢固语,

名称:Satyameva Jayathe,

productId:1520,

productMasterId:1519 ,

productMasterName:Satyameva Jayathe,

productName:Satyameva Jayathe,

productTypeId:1,

productTypeName:电影,

评级:3,

releaseyear:2004,

showGoodName:电影,

观看次数:9910

}

],

resultSize:1171,

pageIndex:1

}

]



我尝试过:



公共类Clas s3

{



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



公共类ListWrapper_Main

{

public List< listwrapper> ResultList {get;组; } $ / $


public string resultSize {get;组; }

public string pageIndex {get;组; }

}



公共类ListWrapper

{

公共字符串channelType {得到;组; }

公共字符串持续时间{get;组; }

public int episodeno {get;组; }

public string genre {get;组; }

public string [] genreList {get;组; }

public List< genres_cls>类型{get;组; }

public int id {get;组; }

public string imageUrl {get;组; }

// public string imageurl {get;组; }

公共字符串语言{get;组; }

公共字符串名称{get;组; }

public int productId {get;组; } $ / $
public int productMasterId {get;组; } $ / $
public string productMasterName {get;组; }

public string productName {get;组; }

public int productTypeId {get;组; } $ / $
public string productTypeName {get;组; }

公共小数点评{get;组; }

public string releaseYear {get;组; }

// public string releaseyear {get;组; }

public string showGoodName {get;组; }

公共字符串视图{get;组; }

}

公共类genres_cls

{

public string personName {get;组; }

}



}

解决方案

将您的JSON粘贴到此工具 [ ^ ]产生:

  public   class 类型
{
public string personName {获得; 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 列表<类型>类型{获取; 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 列表< ResultList> resultList { get ; set ; }
public int resultSize { get ; set ; }
public string pageIndex { get ; set ; }
}



如果JSON开头的额外 [是一个错字,那么你会使用这样的东西:

 RootObject result = JsonConvert.DeserializeObject< RootObject>(yourJsonString); 



如果你的JSON末尾缺少] 是一个错字,那么你会使用这样的东西:

列表与LT; RootObject> result = JsonConvert.DeserializeObject< List< RootObject>>(yourJsonString); 



(这假设您正在使用JSON.NET [ ^ ])


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

}

解决方案

Pasting your JSON into this tool[^] produces:

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:

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:

List<RootObject> result = JsonConvert.DeserializeObject<List<RootObject>>(yourJsonString);


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


这篇关于如何将多个数组的json数据转换为C#MVC中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆