json - Web API返回空JSON对象C#

json - Web API返回空JSON对象C#,第1张

我有一个返回117k JSON对象的Web API。

编辑: API正在调用MySQL来获取117k行数据,将它们放入IEnumerable并通过JSON发送它们

我所看到的只是 [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},...整个页面......

我想问一下某人发生了什么以及如何处理大型JSON转移。希望一次性完成所有操作以避免来回查询(延迟时间)。

函数调用是:

public IEnumerable<Score> Get(int id)
    {
    string mConnectionString = System.Configuration.ConfigurationManager.AppSettings["mysqlConnectionString"];
    MySqlConnection mConn;
    MySqlDataReader mReader;
        List<Score> returnedRows = new List<Score>();
        if (String.IsNullOrEmpty(mConnectionString))
        {
            return returnedRows;
        }
        try
        {
            // prepare the dump query
            MySqlCommand dumpCmd;
            string query = "SELECT * FROM score where id = " id ";";

            using (mConn = new MySqlConnection(mConnectionString))
            {
                using (dumpCmd = new MySqlCommand())
                {
                    dumpCmd.Connection = mConn;
                    dumpCmd.CommandText = query;
                    mConn.Open();

                    mReader = dumpCmd.ExecuteReader(); /
                    if (mReader.HasRows)
                    {
                        while (mReader.Read())
                        {
                            string[] rowCols = new string[mReader.FieldCount]; // there are 20  columns, at least the primary keys are not null
                            for (int i = 0; i < rowCols.Length;   i)
                            {
                                rowCols[i] = mReader.GetString(i);
                            }
                            returnedRows.Add(new Score(rowCols));
                        }
                        mConn.Close();
                        return returnedRows;
                    }
                    else
                    {
                        // should return a 404 cause nothing found
                        mConn.Close();
                    }
                }
            }
        }
        catch (Exception e)
        {
            return returnedRows;
        }
        return returnedRows;
    }

最佳答案:

1 个答案:

答案 0 :(得分:0)

mReader.GetString(i)返回null或列中没有数据。

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复