json_encode() Driving me Crazy
Posted: Wed Aug 07, 2013 7:49 am
Hello:
I've got an application where php constructs a dynamic table. The table is working great, even though it's constructed in the php processing file and passed via a $.getJSON() call. I've got a jQuery dataTable working with it, etc...
Now for the problem. Every row to my table has a <input type="checkbox. This checkbox is used for selecting records. 90% of the time the records will be selected for editing or deletion, at which point I just grabe the id='" . $activityID . "' and run from there.
But.. . there are occassions where I need to grab an array of data. So... my php constructs that particular control as follows:
When I echo the json_encode($rowArray) in a separate <td></td> - it echoes out the following:
So... here's the problem I'm running into:
When I grab the table with jQuery, I can't run JSON.parse() on it without error. Specifically the error is JSON.parse: unterminated Strng
To make a very long story short, in all my testing the parsing breaks at {"startTM":"2013-08-07.
When I copy and paste the actual array values into jQuery variable and then parse the variable, everything works like a charm. Something is happening with the JSON. I'm wondering a few things:
Any assistance with this problem would be greatly appreciated. It is a real stumper. The table is working great, my users love it. There is one task I need to complete, which uses data from this array. After I complete that task, I can move onto another portion of this project, and close up development on this table.
Thanks in advance - Pavilion
I've got an application where php constructs a dynamic table. The table is working great, even though it's constructed in the php processing file and passed via a $.getJSON() call. I've got a jQuery dataTable working with it, etc...
Now for the problem. Every row to my table has a <input type="checkbox. This checkbox is used for selecting records. 90% of the time the records will be selected for editing or deletion, at which point I just grabe the id='" . $activityID . "' and run from there.
But.. . there are occassions where I need to grab an array of data. So... my php constructs that particular control as follows:
Code: Select all
"<input type='checkbox' class='editck' id='editCk_" . $activityID . "' value=" . json_encode($rowArray) . "></input>"After the entire table is constructed, I then echo the whole table as follows:{"startTM":"2013-08-07 11:15:00","endTM":"2013-08-29 13:45:00","Owner":"Duck, Donald","ActivityID":"369"}
Code: Select all
echo(json_encode($outPut)); // $outPut is the variable containing the entire table objectWhen I grab the table with jQuery, I can't run JSON.parse() on it without error. Specifically the error is JSON.parse: unterminated Strng
To make a very long story short, in all my testing the parsing breaks at {"startTM":"2013-08-07.
When I copy and paste the actual array values into jQuery variable and then parse the variable, everything works like a charm. Something is happening with the JSON. I'm wondering a few things:
- Does it muck up things to json_encode specific table row values, and then json_encode the whole table for transport back to the client side?
- If json_encoding data twice before sending it back to the client side is a no-no, then how do I handle a situation like this, I tried NOT json_encoding the $rowArray, but that just created a different set of problems.
Code: Select all
$rowArray = array(
'startTM'=>stripslashes($row['StartTime']),
'endTM'=>stripslashes($row['EndTime']),
'Owner'=>stripslashes($row['Owner']),
'ActivityID'=>stripslashes($activityID),
);Thanks in advance - Pavilion