how to extract data from this array
how to extract data from this array
jonnyenglish89
Posts: 10Questions: 2Answers: 0
Hi, I'd like to extract the faction name from this array but the array’s structure is a little quirky
{
"faction": {
"faction_id": "148999003",
"leader_id": "3800576",
"name": "CarryTheNite",
"power": "0",
"num_members": "50",
"inactive": "0",
"sp_earned": "26510",
"message": "VINI FUSES UP NEXT",
"total_rating": 1032609,
"recruitment_status": "1",
"min_rating": "0",
"min_level": "19",
"total_level": "0",
"vote_id": "3800576",
"votes": 0,
"max_members": 50,
"guild_points": "26510",
"faction_key": "4f0"
}
}
I've tried this to no avail:
$(document).ready(function(){
$('#data-table').DataTable({
"ajax" : "source.json",
"columns" : [
{ "faction" : "name" }
]
});
});
any help would be appreciated
This discussion has been closed.
Answers
did you try
No, I hadn’t but when I did I got this error “DataTables warning: table id=data-table - Ajax error.”
did you define all of your columns that are being displayed (you need to do that if your data is in an array of json objects.
Thanks for your help so far. I’ll continue to search the forum for an answer
There is no
columns.faction
property in DataTables, so that won't work.Can you upload
source.json
so we can see the exact structure of the file please?Allan
Sure, I changed the ext from .json to .txt so i could upload it
In that JSON file, is there an array that you want to have displayed as the rows in the table? I see a lot of different objects, but there doesn't appear to be any suitable arrays.
Allan
Ultimately, I wanted to display:
(conquest_data -> zone_data -> “name” + “my_guild_points”)
into a table that I could filter and sort as required… it’s a shame it doesn’t seem possible with data tables as they would have been perfect
my_guild_points
appears to be an integer value:What is the per row data point here? For example load this page and click the "Ajax" tab below the table. You will see an array of objects. Each array entry is a row in the table.
What do you want to show per row?
Allan
this is what I'd like to be displayed in the data table
Hope that helps
You'd need to modify the JSON structure (either on the server-side or the client-side, it doesn't really matter) before DataTables sees it. DataTables needs an array of items, where each item is a row to be shown - the item can be a complex object, but fundamentally it must be an array.
Allan
Ok, thanks for your help!