-1

I have a web API returning 117k JSON objects.

Edit: The API is calling MySQL to fetch 117k rows of data, putting them into a IEnumerable and sending them through JSON

All I see is [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},... the entire page...

I wanted to ask how someone what is happening and how you would handle a large JSON transfer. Prefer to get it all in one go to avoid querying back and forth (delay time).

The function call is this:

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;
    }
lzc
  • 1,645
  • 5
  • 27
  • 41
  • 2
    "I wanted to ask how someone what is happening" Ask whoever built the API. How would we know? You've given us no useful information to go on. – ceejayoz Jun 11 '15 at 19:23
  • 1
    what is your code?! Can you put a part of your API code in here? – Kamiel Ahmadpour Jun 11 '15 at 19:26
  • @ceejayoz Sorry I had to make you assume, but its exactly as stated. API calls db, db retrieves a large amount of rows, sends over to the client. – lzc Jun 11 '15 at 19:31
  • I think the problem is with the `Score` class. According to the documentation the other part of the code is okay. https://msdn.microsoft.com/en-us/library/9kcbe65k%28v=vs.110%29.aspx – inf3rno Jun 11 '15 at 19:45
  • Yes youre right @inf3rno The class has to be serializable in order to pass through JSON – lzc Jun 11 '15 at 19:47

1 Answers1

0

Either mReader.GetString(i) is returning null or you have no data in the columns.

Chris McCall
  • 10,317
  • 8
  • 49
  • 80