Search code examples
javascriptsqljsonjqgridquotes

Missing quotes in JSON object. How to add them in?


I've got a slight problem when passing parsed JSON variabled through jqGrid. I am querying a MS Access .mdb file. The problem is there is an ID field which is an autonumber integer field in MS Access and does not have quotes when queried. jqGrid doesn't like this and that's why it is not showing the ID value in the table.

 var SQL = "SELECT * FROM test";
 var resultSet = myDB.query(SQL);
// resultSet will yield [{"ID":1,"name":"albert","9999999999"},{"ID":2,"name":"peter","8888888888"}]
 var mydata = JSON.parse(resultSet)

notice above how resultSet does not have quotes on ID value but the rest do. This is resulting in a table without value in ID column. How do I add quotes to the ID value before it get's parsed via JSON?

Thank you.

enter image description here The whole code.. enter image description here


Solution

  • jqGrid can work with integers exactly like with strings. So you don't need to change numbers to strings. The JSON which you posted in your previous question contains id instead of ID. JavaScript is case sensitive language. I suppose that you will see values in id column if you replace

    {name:'ID',index:'ID', width:60, sortable:false},
    

    to

    {name:'id', width:60, sortable:false},
    

    Additionally I recommend you to remove index property from comModel.