Jump to content

xcandiottix

Members
  • Posts

    330
  • Joined

  • Last visited

    Never

Everything posted by xcandiottix

  1. Sorry for the misunderstanding initially dcro2. Your way seems to work perfectly. Thank you very much for your assistance!
  2. $liveArray = array(); //Add needed data to JSON creation with required html $liveArray['ID'] = $ID; $liveArray['current'] = number_format(($checkPrice - $deduct),2); $savings = 1-@($checkPrice / $originalPrice); $savings = round($savings, 4); $liveArray['currentSavings'] = $savings*100; $liveArray['place'] = "ON"; $liveArray['buy'] = "OFF"; if($Status == "ON"){ $liveArray['pb'] = "ON"; } else{ $liveArray['pb'] = "OFF"; } $data = json_encode($liveArray); $liveArray['Stream'] = $_GLOBALS['History']; $data = json_encode($liveArray); $myFile = '../json/auctions/'.$ID.'-live.js'; $fh = fopen($myFile, 'w') or die('can\'t open file'); fwrite($fh, $data); fclose($fh); //Set file access chmod('../json/auctions/'.$ID.'-live.js', 0644); //TESTING echo $data; unset($liveArray, $data, $myFile, $fh); Sorry, I didn't show the array construction. Stream already part of the array but it's forcing quotes after the : and before the [ if that makes sense. That's the code that creates the JSON. There's some other things being added to the JSON but they don't affect the problem I'm having. To simplify my issue, I'm using php to create liveArray with a few different json object pairs (name:value). At the end I want to attach an array (name:["value 1","value 2","value 3"]). The problem is that once the array is created, there is an error in the way the array is entered into the json file. The error being that the json_encode() command is placing a double quote BEFORE the opening bracket of the array (name:"["value1...). The double quote between the : [ causes the following double quotes around the array vaules gets escaped (name:"[\"value 1\"]) therefore it cannot be parsed later on when I call it to populate a div.
  3. I'm only working with PHP 5.2 so I don't have the option to include one of the bitmask arguments while encoding an array. I was wondering if someone had a work around for this: $_GLOBALS['History'] .= '['; while($row3 = @mysql_fetch_array($result3)){ $number = $row3['db_Id']; $time = $row3['db_Timestamp']; date_default_timezone_set('America/Phoenix'); $time = date("l M j g:i:s a T Y", $time); $_GLOBALS['History'] .= '"<img src=\'../images/avatar/'.md5($row['db_UserId']).'.jpg\'>'.$row['db_UserId'].'<br>'.$time.'<br>",'; unset($alert); } $_GLOBALS['History'] .= '"0"]'; //SETS LAST RUN AS SOMETHING TO FINALIZE LAST COMMA OF WHILE LOOP I get it to the JSON like so: $liveArray['Stream'] = $_GLOBALS['History']; $data = json_encode($liveArray); $myFile = '../json/auctions/'.$ID.'-live.js'; $fh = fopen($myFile, 'w') or die('can\'t open file'); fwrite($fh, $data); fclose($fh); //Set file access chmod('../json/auctions/'.$ID.'-live.js', 0644); //TESTING echo $data; unset($liveArray, $data, $myFile, $fh); In my JSON file I'll see: {"Stream":"[\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"<img src='..\/images\/avatar\/d41d8cd98f00b204e9800998ecf8427e.jpg'><br>Wednesday Dec 31 5:00:00 pm MST 1969<br><br>\",\"0\"]"} But the proper format of a json array should be {"Stream":["item one","item two","etc"]"} instead of {"Stream":"["item one","item two","etc"]""} So how can I avoid that " after the : ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.