Filemaker php api:将每个循环变量编码为json


Filemaker php api: encode for each loop variables to json

我被要求通过filemaker php api提供json对象的filemaker数据。

我已经能够在单个记录

上使用以下命令
 echo json_encode(array($namefamily, $namefirst, $dob, ));

现在我需要在我的每个循环中编码为json -不确定如何让它与连接变量一起工作:

$records = $result->getRecords();
foreach($records as $record){
    echo' ' . $record->getField('NameFirst') . ' | ' . $record->getField('NameFamily') .' ';
}

与之前的答案类似,但使用工作的FileMaker API语法…

$records = $result->getRecords();
foreach($records as $record){
    $data[] = array( 
                    'NameFirst' => $record->getField("NameFirst"),
                    'NameFamily' => $record->getField("NameFamily")
                   );
}
echo json_encode($data);

你应该使用数组作为它的容器,希望能有所帮助。

$records = $result->getRecords();
$data = new Array()
foreach($records as $record){ 
$data.push({"firstname" -> $record->getField, "lastname" -> $record-> })
}
echo json_encode($data)