이 json 파일을 반복하고 결과를 나누고 싶은 원치 않는 요소를 필터링하여 고객 목록 또는 공급자 json 파일 목록을 가지려고합니다.
{
"$descriptor": "Test",
"$resources": [
{
"$uuid": "281d393c-7c32-4640-aca2-c286f6467bb1",
"$descriptor": "",
"customerSupplierFlag": "Customer"
},
{
"$uuid": "87a132a9-95d3-47fd-8667-77cca9c78436",
"$descriptor": "",
"customerSupplierFlag": "Customer"
},
{
"$uuid": "8a75345c-73c7-4852-865c-f468c93c8306",
"$descriptor": "",
"customerSupplierFlag": "Supplier"
},
{
"$uuid": "a2705e38-18d8-4669-a2fb-f18a87cd1cc6",
"$descriptor": "",
"customerSupplierFlag": "Supplier"
}
]
}
예를 들면
{
"$uuid": "281d393c-7c32-4640-aca2-c286f6467bb1",
"$descriptor": "",
"customerSupplierFlag": "Customer"
},
{
"$uuid": "87a132a9-95d3-47fd-8667-77cca9c78436",
"$descriptor": "",
"customerSupplierFlag": "Customer"
},
내 PHP 코드는
$array = json_decode($result, true);
for ($i = 0; $i < count($array['$resources']); $i++){
foreach ($array['$resources'][$i]['customerSupplierFlag'][Customer] as $item)
{
// do what you want
echo $item['customerSupplierFlag' ]. '<br>';
echo $item['$uuid'] . '<br>';
}
}
나는 며칠 동안 이것으로 어려움을 겪어 왔으며 지금은 같은 기사를 검토하는 것처럼 보이며 지금은 어떤 제안이라도 감사 할 것입니다.
$data = file_get_contents('./your_json_data.txt');
$json = json_decode($data, 1);
$resources = $json['$resources'];
$suppliers = array();
$customers = array();
foreach ($resources as $rkey => $resource){
if ($resource['customerSupplierFlag'] == 'Customer'){
$customers[] = $resource;
} else if ($resource['customerSupplierFlag'] == 'Supplier') {
$suppliers[] = $resource;
}
}
header('Content-Type: application/json');
echo json_encode($customers);
echo json_encode($suppliers);
die();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다