Error parsing JSON

Error parsing JSON

maheshnmurthimaheshnmurthi Posts: 5Questions: 0Answers: 0
edited February 2011 in General
Hello,

I am using DataTables v1.7.5. I am using the Server Side processing to get data from the server. Farther below is the JSON that is returned by the server. But everytime I try to load the page I am getting:

DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.

I tried searching in the forums and done the following:

a) looked into apache log records for some error which would lead me onto something
b) removed newline characters and carriage returns
c) used json_encode to encode the string before sending it back to the client.
d) b & c together.

But I am still stuck at the same place.

JSON from the Server:

[code]
{"sEcho": 1,
"iTotalRecords": 46,
"iTotalDisplayRecords": 10,
"aaData": [
["A Buffer Resource Allocation Problem", "", "BufferResourceAllocation.pdf", "" ],
["A Multimodal Function", "", "Multimodal.pdf", "multimodal.m" ],
["Ambulances in a square", "TextFileToGo.txt", "AmbulanceLocationsInSquare.pdf", "ambulance.m" ],
["Assemble to order", "", "AssembleToOrder.pdf", "Assemble_to_Order.m" ],
["Baby Call Center", "TextFileToGo.txt", "BabyCallCenter.pdf", "BabyCall.m" ],
["Bike Sharing in Fakeville", "BikeSharingReadme.txt", "BikeSharing.pdf", "BikeSharingData.csv" ],
["Booking limits at a hotel: Baby", "", "BABY HOTEL.pdf", "BabyHotel.m" ],
["Booking limits at a hotel: Full", "", "HOTEL FULL.pdf", "HotelFull.m" ],
["Container Freight", "", "ContainerExample.pdf", "ContainerFreight.m" ],
["Continuous Newsvendor", "TextFileToGo.txt", "ContinuousNewsvendor.pdf", "Newsvendor.m" ]
] }
[/code]

Any help is appreciated.

Thanks,
MNM

Replies

  • maheshnmurthimaheshnmurthi Posts: 5Questions: 0Answers: 0
    Ohh.. I forgot to add, I also validated the generated JSON with http://jsonlint.com/ and it returns saying its Valid JSON.
  • allanallan Posts: 63,302Questions: 1Answers: 10,431 Site admin
    Are you able to give us a link to the page where this is happening ( http://datatables.net/contact if you don't want to make it public).

    One thing, although it won't result in the above error, is that iTotalDisplayRecords and iDisplayRecords should be the same unless you have a filter applied.

    Allan
  • maheshnmurthimaheshnmurthi Posts: 5Questions: 0Answers: 0
    Unfortunately the website won't go live until I have finished developing it and got it approved by my Professor. I am currently developing it on my laptop and I am using the server side processing code that is almost similar to the one in this example: http://www.datatables.net/examples/data_sources/server_side.html

    I have only added some new-line characters which I needed to make more sense when I was writing it to a file.

    The other thing I did was to swap the single quotes for the double quotes in order to record the new line characters before writing to a file.

    Seems like the example for server side has recently been enhanced and expanded. Should I give it a try before I get back?

    Thanks,
    Mahesh
  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited February 2011
    Ignore me; I replied without understanding the problem. This edit deletes my Tom-foolery. ;-)
  • maheshnmurthimaheshnmurthi Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Thanks for your valuable input. I am trying to implement it in a different fashion by styling the DOM and I build up the DOM using server side scripting. Do you think its a good idea? Also, could you send an example of this http://www.datatables.net/examples/server_side/row_details.html

    I have not done extensive JavaScript or PHP programming, so it would be nice if you could send a working example so that I can learn how it has been done, both the PHP and JavaScript.

    Also, could I use the demo_table.css file and modify it suitably? Thank you for your time.

    Cheers,
    Mahesh
  • maheshnmurthimaheshnmurthi Posts: 5Questions: 0Answers: 0
    Hi Allan,

    I have done that example by building the DOM object using PHP script. My table size is just about 50 to 100 rows, so I don't think its a bad idea. Also, I am just wondering, in the example in hiding and showing details, could I do it with PHP only because I need to add links to files from the database.

    Thanks,
    Mahesh
This discussion has been closed.