-1

I've fetch a list of schools with their corresponding columns from my database which has a 1000+ rows then convert it to JSON and pass it to my view and parse it using

$.parseJSON('@Html.Raw(Model.subChoiceJsonString)')

then place it to an array

ko.observableArray($.parseJSON('@Html.Raw(Model.subChoiceJsonString)'));

but my problem is it does not work , but it works when there the number of rows are much smaller.

I'm thinking that it can't be parse due to a limitation of a string in Javascript. Is that correct? How can I make it work?

George Cummins
  • 28,485
  • 8
  • 71
  • 90
Allen
  • 53
  • 9

3 Answers3

6

parseJSON() takes a string.
You're passing it an incorrectly-escaped string literal, which will break if the JSON has single quotes.

Instead, you should use a regular Javascript literal:

var myObject = @Html.Raw(Model.subChoiceJsonString);

Note that this will break if the JSON has U+2028 LINE SEPARATOR; see here.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Yeah that seems like it would be huge... Instead, I would add pagination or something similar to your control. I don't know why a user would want to see 1000+ items at once anyways. Instead, only display 50-100 at a time and allow the user to paginate through the full list.

DigitalZebra
  • 39,494
  • 39
  • 114
  • 146
  • JSON.parse should have no trouble parsing that. – SLaks May 30 '13 at 14:44
  • i've used 80,000 row DB table exports in JSON (15mb total footprint); takes about half a sec to parse, but works just fine and instantly after that. – dandavis May 30 '13 at 15:12
0

There are no size limits in HTTP itself, but maybe your server framework imposes some limit. Or maybe which larger responses your HTTP request times out.

blpsilva
  • 69
  • 1
  • 3