我如何解析我的数组到我的模型

时间:2014-05-10 14:02:29

标签: c# arrays json parsing model

我做了一个ajax帖子并将我的json字符串化并将数据发送到我的控制器方法: 控制器收到的数据如下所示:

“[\”0041300201 \“,1610612764,\”WAS \“,”华盛顿“,2772,”Trevor Ariza“,”F“,\”\“,\”37:20 \ “7,10,0.7,6,6,1,2,4,0.5,1,5,6,2,1,0,0,3,22,18]”

我的控制器方法:

public void addBoxScore(string playerstats) 
    {
       Games gamestats = new Games();
       gamestats.GAME_ID = playerstats[0];
       gamestats.TEAM_ID = playerstats[1];
       gamestats.TEAM_ABBREVIATION = playerstats[2].ToString();
       gamestats.TEAM_CITY = playerstats[3].ToString();
       gamestats.PLAYER_ID = playerstats[4];
       gamestats.PLAYER_NAME = playerstats[5].ToString();
       gamestats.START_POSITION = playerstats[6].ToString();
       gamestats.COMMENT = playerstats[7].ToString();

       gamestats.MIN = playerstats[8];
       gamestats.FGM = playerstats[9];
       gamestats.FGA = playerstats[10];
       gamestats.FG_PCT = playerstats[11];
       gamestats.FGTHREEM = playerstats[12];
       gamestats.FGTHREEA = playerstats[13];
       gamestats.FGTHREE_PCT = playerstats[14];
       gamestats.FTM = playerstats[15];
       gamestats.FTA = playerstats[16];
       gamestats.FT_PCT = playerstats[17];
       gamestats.OREB = playerstats[18];
       gamestats.DREB = playerstats[19];
       gamestats.REB = playerstats[20];
       gamestats.AST = playerstats[21];
       gamestats.STL = playerstats[22];
       gamestats.BLK = playerstats[23];
       gamestats.TO = playerstats[24];
       gamestats.PF = playerstats[25];
       gamestats.PTS = playerstats[26];
       gamestats.PLUS_MINUS = playerstats[27];


    }

当我这样做时,gamestats.Game_ID变为“91”而不是“0041300201”,正如我想要的那样。

1 个答案:

答案 0 :(得分:0)

请使用此数组或字符串列表而不是仅使用字符串。像这样

public void addBoxScore(string[] playerstats)