Gson Requested unknown parameter

Gson Requested unknown parameter

shinkshinkshinkshink Posts: 3Questions: 0Answers: 0
edited March 2014 in General
Hi,

I'm having problem with parsing json object to data table:

The debug report:
http://debug.datatables.net/ocitol

fiddle:
http://jsfiddle.net/eYKaK/

Error message:
DataTables warning (table id = 'unilevel_1'): Requested unknown parameter 'name' from the data source for row 0

Response Result:
[{"name":"Braw bee"}]

Entity:
[code]
public class TestKing {
String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
[/code]

Controller
[code]
public static Result listAssociates() {
TestKing test1 = new TestKing();
test1.setName("Braw bee");
List listTest = new ArrayList();
listTest.add(test1);
Gson gson = new Gson();
String json = gson.toJson(listTest);
return ok(json);
}
[/code]


View
[code]
var TableManaged = function () {
return {
//main function to initiate the module
init: function (data) {
alert("object: "+ data);
if (!jQuery().dataTable) {
return;
}

// begin first table
$('#unilevel_1').dataTable({

"aaData": data,
"aoColumns": [
{ "bSortable": false,
"sTitle": "FULL NAME",
"mDataProp": "name"}

]
});
jQuery('#unilevel_1_wrapper .dataTables_filter input').addClass("form-control input-medium"); // modify table search input
jQuery('#unilevel_1_wrapper .dataTables_length select').addClass("form-control input-xsmall"); // modify table per page dropdown

}

};

}();
[/code]

Replies

  • shinkshinkshinkshink Posts: 3Questions: 0Answers: 0
    Here is what i found so far:

    when I used data2 the datatables render properly while if i used data (comes from response)
    i get an error.

    alert output:
    [quote]
    object: [{"name":"Braw bee"}] **** data2: [object Object]
    [/quote]


    [code]
    data2 =[{"name":"Braw bee"}];

    alert("object: "+ data +" **** "+"data2: "+data2);
    // begin first table
    $('#unilevel_1').dataTable({

    "aaData":data2,
    "aoColumns": [
    { "mDataProp": "name",
    "bSortable": false,
    "sTitle": "FULL NAME",
    }
    ]
    });
    [/code]
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    From your debug trace:

    > "aaData": "[{\"name\":\"Braw bee\"}]",

    You are passing in aaData as a string - not an array. You could do:

    [code]
    aaData: JSON.parse( data )
    [/code]

    Allan
  • shinkshinkshinkshink Posts: 3Questions: 0Answers: 0
    That is just awesome.. Works at is should be,

    I appreciate you effort Allan! Thank you.
This discussion has been closed.