Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Newtonsoft.Json JObject.ToString() Out of Memory exception

$
0
0

Hello:
I have the following piece of code to get a JSON string

 public static string ReturnResults(Results results)
        {
            dynamic JObject = new JObject();
            JObject.success = results.success;
            JObject.statuscode = results.statuscode;
            JObject.data = results.data;
            JObject.errormessage = results.errormessage;
            JObject.additionalmessage = results.additionalmessage;
            return JObject.ToString();

        }

The "results.data" actually contains the results from the back end database table. When the data represents thousands of rows, I get out of memory exception.

Exception of type 'System.OutOfMemoryException' was thrown.

What's the efficient way to do this? Instead of a dynamic object, I can create a class and then serialize? Any help will be appreciated.


Viewing all articles
Browse latest Browse all 9386

Trending Articles