We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13735
    • 62 Posts
    Hello,

    I’ve probably discovered a bug in the toJSON function. Maybe I’m just doing something wrong but what I’m trying to accomplish does not work. It’s hard to explain by words, so I made a short video. I’m using the rc3 of Revo.

    http://downloads.josefbrandl.com/posts/2010-08-19/jsonbug.mov 10MB


    [Edit:]
    I’ve tested it with php’s json_encode and it doesn’t work either. Here’s my code:

    <?php
    $settings = array(
        'parentId' => 31,
        'thumbWidth' => 110,
        'thumbHeight' => 110,
        'thumbSpacingX' => 12,
        'thumbSpacingY' => 12,
        'thumbBorder' => 3,
        'bigWidth' => 1024,
        'bigHeight' => 1024,
    );
    
    $modx->regClientStartupScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
    $modx->regClientStartupScript('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js');
    $modx->regClientStartupScript('assets/components/ggViewer/ggViewer.js');
    
    include_once ($modx->getOption('core_path') . "components/gallerygear/gallerygear.class.php");
    $gg = new GalleryGear();
    
    $data['settings'] = $settings;
    
    foreach($gg->getPhotos($settings['parentId']) as $photo) {
        $thumb = $photo->setResizedPhoto('crop', $settings['thumbWidth'], $settings['thumbHeight']);
        $big = $photo->setResizedPhoto('fullShrinkOnly', $settings['bigWidth'], $settings['bigHeight']);
    
        $data['photos'][] = array(
            $thumb->getWebURL(),
            $big->getWebURL()
        );
    }
    
    return '<ul class="ggViewer">' . json_encode($data) . '</ul>';
    ?>


    My workaround was simply to define some keys. But I still don’t understand why it doesn’t work.

    thanks
    JB
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      You probably should upgrade to the public release version of MODx.

      What version of PHP are you using? the json_encode() function isn’t available until 5.2... but I think that’s a requirement of Revo anyway...

      I’m not sure I understood your test. What are you expecting to get after running that?
        • 13735
        • 62 Posts
        I tried to save some kB’s by not using keys. Maybe a pattern like

        ..., [
        ["value", "value"],
        ["value", "value"],
        ], ...

        is not allowed. If I had known that it’s not modx specific (as the test with json_encode() proves) then I would never have started this thread. The workaround to this problem is simple (see above), so this thread is not too important for me wink But anyway if a "json expert" reads this, it would be great if he/she could confirm that this is a real limitation.