• Resolved MrWrighty

    (@mrwrighty)


    Hi

    I’m trying to parse a Tablepress table using my own Javascript to display in IOS and treating the post_content as JSON, but I cannot get the table to read correctly as JSON data.

    The data as stored does not look or function like proper JSON data. Even testing the data using export to JSON doesn’t seem to create proper formatted JSON data.

    Data is stored as Column Name, Column Name etc followed by data, data as opposed to Column Name:Data, Column Name:Data

    Eg

    “data”:[[“Pos”,”Team”,”P”,”W”,”L”,”D”,”BP”,”LP”,”Pts”,””],[“”,””,””,””,””,””,””,””,””,””],[“<font color=’red’><b>C<\/b><\/font>”,”<b>Rattlers<\/b>”,”<b>22<\/b>”,”<b>17<\/b>”,”<b>5<\/b>”,”<b>0<\/b>”,”<b>170<\/b>”,”<b>153<\/b>”,”<b>323<\/b>”,””],[“<font color=’red’><b>R\/U<\/b><\/font>”,”Team A”,”22″,”17″,”5″,”0″,”170″,”147″,”317″,””],[“3″,”Team B”,”22″,”15″,”7″,”0″,”150″,”137″,”287″,””],[“4″,”Team C”,”22″,”10″,”9″,”3″,”115″,”120″,”235″,””],[“5″,”Team D”,”22″,”12″,”10″,”0″,”120″,”105″,”225″,””],[“6″,”Team E”,”22″,”10″,”12″,”0″,”100″,”121″,”221″,””],[“7″,”Team F”,”22″,”10″,”11″,”1″,”105″,”113″,”218″,””],[“8″,”Team G”,”22″,”10″,”10″,”2″,”110″,”101″,”211″,””],[“9″,”Team H”,”22″,”11″,”11″,”0″,”110″,”94″,”204″,””],[“10″,”Team I”,”22″,”7″,”15″,”0″,”70″,”89″,”159″,””],[“11″,”Team J”,”22″,”5″,”17″,”0″,”50″,”69″,”119″,””],[“12″,”Team K”,”22″,”5″,”17″,”0″,”50″,”61″,”111″,””]]

    I want to read the column names and data as posted in the post_content to redisplay in an IOS application.

    Using the following Javascript does not return any data:

    jsonArray = $.parseJSON(xhr.responseText);
    var html = “<table align=’center’ width=’99%’ cellpadding=’4′ border=’0′ style=’margin-left: 2px;font-size: 10pt; border-collapse: collapse;’><thead><tr><td>Pos</td><td>Team</td><td>P</td><td>W</td><td>L</td><td>D</td><td>BP</td><td>LP</td><td>Pts</td></tr></thead><tbody>”;
    for(i=0; i < jsonArray.length; i++)
    {
    pos = jsonArray[i].Pos;
    team = jsonArray[i].Team;
    p = jsonArray[i].P;
    w = jsonArray[i].W;
    L = jsonArray[i].L;
    D = jsonArray[i].D;
    BP = jsonArray[i].BP;
    LP = jsonArray[i].LP;
    Points = jsonArray[i].Pts
    html += “<tr><td align=’left’><font size=’+1′><b>”+pos+”</b><td><b>”+team+”</b></font></td></tr><tr><td>”+p+”</td><td>”+w+”</td><td>”+L+”</td><td>”+D+”</td><td>”+BP+”</td><td>”+LP+”</td><td>”+Points+”</td></tr>”;
    }

    html += “</table>”;

    Thanks

    https://wordpress.org/plugins/tablepress/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Both the data for a table in the post_content field as well as the exported JSON file are valid JSON. It might just have a different structure than what you are expecting. The table is not stored as an array of objects there, but as an array of arrays.
    That is, the table is an array (of rows), and each row is again an array (of cells).
    In your for loop, you will therefore just have to add a second for loop to go through each row.

    Regards,
    Tobias

    Thread Starter MrWrighty

    (@mrwrighty)

    Thanks Tobias

    Sorted.

    Regards

    Nick

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Thread Starter MrWrighty

    (@mrwrighty)

    Having to post something to unsubscribe from followups which is rather a pain.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yeah, that’s a bit ugly. But if nobody posts in this thread, you wouldn’t get more mails 🙂

    Best wishes,
    Tobias

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Parsing Tablepress table with PHP’ is closed to new replies.