We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7575
    • 85 Posts
    hi I have a snippet that returns a json array that I put back in a php array later. I do this to be able to call the snippet in another snippet and get the array it produces

    here is the inner snippet:
    $myCountries = $xpdo->getCollection('Countries');
    foreach ($myCountries as $country) {
       $countries[$country->get('idCountries')]=$country->get('Country_'.$lang);
    }
    //print_r($countries); // used to check if $countries contains all the wanted strings
    return $modx->toJson($countries);


    part of the outer snippet
    $mycountries=$modx->fromJson($modx->runSnippet('getcountries',array('lang' => $lang)));
    //print_r ($mycountries);


    here is the problem: the print_r of the $countries in the inner snippet gives:
    Array ( [AT] => Oostenrijk [BE] => Belgi� [DE] => Duitsland [DK] => Denemarken [ES] => Spanje [FR] => Frankrijk [GB] => Verenigd Koninkrijk [IE] => Ierland [IT] => Itali� [LU] => Luxemburg [NL] => Nederland [PT] => Portugal )

    while the outer snippet print_r of $mycountries gives:
    Array ( [AT] => Oostenrijk [BE] => [DE] => Duitsland [DK] => Denemarken [ES] => Spanje [FR] => Frankrijk [GB] => Verenigd Koninkrijk [IE] => Ierland [IT] => [LU] => Luxemburg [NL] => Nederland [PT] => Portugal )

    notice the part in bold:
    België and Italië have dissapeared in the Json conversion.
    if I printout the Json conversion of $countries in the inner snippet I get:
    {"AT":"Oostenrijk","BE":null,"DE":"Duitsland","DK":"Denemarken","ES":"Spanje","FR":"Frankrijk","GB":"Verenigd Koninkrijk","IE":"Ierland","IT":null,"LU":"Luxemburg","NL":"Nederland","PT":"Portugal"}

    with a "null" for BE and IT

    can anyone tell me what I am doing wrong?




      www.tornooi.net online database for (sport) events in dutch.
      To be redesigned, rewritten to modx with multiple languages...
      ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
      • 1778
      • 659 Posts
      Hello

      Not sure at all if it can solve your problem but it seems to be a trouble with encoding (like with strtodate() that returns ISO format and not utf8 )... did you try something like that :

      $mycountries=utf8_encode($modx->fromJson($modx->runSnippet('getcountries',array('lang' => $lang))));
      //print_r ($mycountries);
      


      Cheers
        • 7575
        • 85 Posts
        anso, your reply showed me how to fix it:
        $countries[$country->get('idCountries')]=utf8_encode($country->get('Country_'.$lang));
        }


        tnx a lot!
          www.tornooi.net online database for (sport) events in dutch.
          To be redesigned, rewritten to modx with multiple languages...
          ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
          • 1778
          • 659 Posts
          Glad you have it to work ^_^
          Have swing