1

我试图将 Judy 改编为我的代码,几乎将其用作传统的 php 数组,但我在尝试访问多维数组时遇到了麻烦。每次我尝试打印嵌套键值时,我都会得到一个 NULL。

  1. 我如何迭代我的结果?
  2. 我如何将此结构编码为json?每次我尝试时,我都会得到一个空括号“{}”

我的代码:

/**
 * This method parses the content of XML body
 * Array of objects to spare more memory usage
 * @param $xml object SimpleXml Object
 * @param $timeRequest array this second param brings the time_request value along with the url
 */
private function parseXmlContent($xml, $timeRequest)
{
    $counter = 0;
    $forecast = new \Judy(Judy::INT_TO_MIXED);

    foreach ($xml->point as $key => $value):

        $forecast[$counter] = $this->initJudy($value, $timeRequest, count($value);            
        $counter++;

    endforeach;

    $this->sucess++;
    $this->results[$this->results->nextEmpty(0)] = $forecast;
}

private function initJudy($value, $timeRequest, $length)
{
    $judy = new \Judy(Judy::STRING_TO_MIXED);
    $judy['timestamp'] = (string)$value->data[0];
    $judy['time_request'] = $timeRequest[0]->time_request;
    $judy['latitude'] = (string)$value->data[1];
    $judy['longitude'] = (string)$value->data[2];

    $j = 0;
    for ($i = 3; $i < $length; $i++) {
        $attribute = $this->variables[$j];
        $judy[$attribute] = (string)$value->data[$i];
        $j++;
    }

    return $judy;

}
4

0 回答 0