Get data with JSON: complex structure
Get data with JSON: complex structure
foppapedretti
Posts: 2Questions: 1Answers: 0
How can I show colums (id, name) with JSON data with this structure?
{
"3":{"id":"3","name":"John"},
"4":{"id":"4","name":"Travolta"},
"5":{"id":"5","name":"Harry"}
"6":{"id":"6","name":"Potter"}
}
This discussion has been closed.
Answers
JSON DATA:
{"servertime":"Mon May 18 19:06:59 IST 2015","status":"Success","message":"Camp Number details refreshed successfully","rows":[{"cnumberid":1,"cnumber":"25552","cnumbercampaignid":1,"cnumberstartdate":"Dec 5, 1986 10:00:00 AM","cnumberenddate":"Dec 4, 1986 10:00:00 AM"},{"cnumberid":2,"cnumber":"1234567890","cnumbercampaignid":1,"cnumberstartdate":"Dec 11, 1986 10:00:00 AM","cnumberenddate":"Dec 30, 1986 10:00:00 AM"},{"cnumberid":7,"cnumber":"87485","cnumbercampaignid":1,"cnumberstartdate":"Dec 9, 1986 10:00:00 AM","cnumberenddate":"Dec 8, 1986 12:00:00 PM"},{"cnumberid":9,"cnumber":"56262","cnumbercampaignid":1,"cnumberstartdate":"Dec 5, 1986 10:00:00 AM","cnumberenddate":"Dec 6, 1986 10:00:00 AM"},{"cnumberid":10,"cnumber":"010120","cnumbercampaignid":1,"cnumberstartdate":"Dec 13, 1986 10:00:00 AM","cnumberenddate":"Dec 20, 1986 10:00:00 AM"},{"cnumberid":6,"cnumber":"11110","cnumbercampaignid":3,"cnumberstartdate":"Feb 3, 2001 1:45:56 PM","cnumberenddate":"Feb 3, 2001 1:45:56 PM"},{"cnumberid":5,"cnumber":"1112","cnumbercampaignid":5,"cnumberstartdate":"May 4, 2015 12:00:00 AM","cnumberenddate":"May 7, 2015 12:00:00 AM"}],"issort":false}
Java Script for read json:
$.ajax({
type: method,
data:parameters,
url: URL,
dataType:dataType,
timeout: 30000,
catch :false,
success: function (data) {
text=data;
$.each(data.rows,function(i,obj)
{
$("#campaignalgotable").append("<tr><td id=campailgoname>"+obj.campaignalgoname+"</td>"+"<td id=campaalgodesc>"+obj.campaignalgodesc+"</td></tr>");
});
},
async: false,
error: function (jqXHR, textStatus, errorThrown) {
throwAjaxErrorToUser(jqXHR, textStatus, errorThrown);
}
});
Jsp Page:
This Is Success full laod json data in Data Table
@foppapedretti - DataTables does not currently accept an object of objects to display. It needs to be an array of object. You can use the
ajax.dataSrc
option as a function to perform the conversion in if you are using the DataTables Ajax options.Allan
I solved by generating a json file like this:
[
{"id":"3","name":"John"},
{"id":"4","name":"Travolta"}
]
Thanks anyway :-)