PHP로 JSON 데이터 필터링

교활한 사기꾼

이 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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

PHP에서 JSON 데이터 필터링

분류에서Dev

Flutter는 json 데이터를 고유 데이터로 필터링

분류에서Dev

현재 날짜로 Json 데이터 필터링

분류에서Dev

PHP 필터링 JSON 배열

분류에서Dev

ngModel로 JSON 필터링

분류에서Dev

angularjs로 json 필터링

분류에서Dev

컨트롤러에서 올바른 방법으로 json 데이터 필터링

분류에서Dev

드롭 다운으로 각도를 사용하여 json 데이터 필터링

분류에서Dev

특정 속성 및 값을 기반으로 JSON 데이터 필터링

분류에서Dev

날짜 범위를 기반으로 JSON 데이터를 필터링하는 Angularjs

분류에서Dev

속성으로 데이터 필터링

분류에서Dev

NSPredicate로 필터링-데이터 유형?

분류에서Dev

AJAX로 데이터 필터링

분류에서Dev

PHP에서 Json 항목 필터링

분류에서Dev

노치 필터와 버터 워스로 데이터 필터링

분류에서Dev

값으로 JSON 필터링 Spring Java

분류에서Dev

AngularJS-변수로 Json 필터링

분류에서Dev

Ansible : JSON 필터링

분류에서Dev

amCharts : JSON 필터링

분류에서Dev

Python : 일부 json 객체를 기반으로 Json 파일에서 데이터 필터링?

분류에서Dev

선택 요소를 json 데이터로 채우고 json의 필터링 된 콘텐츠를 반환합니다.

분류에서Dev

C #의 동적 필터 쿼리로 복잡한 JSON 필터링

분류에서Dev

AngularJS 필터로 일부 JSON 값 필터링

분류에서Dev

PHP에서 onchange로 데이터 목록 필터링

분류에서Dev

PHP로 json 데이터 반환 시도

분류에서Dev

json 배열에서 필요한 데이터 필터링

분류에서Dev

"데이터"로 JSON 데이터 반환

분류에서Dev

이름이 같은 JSON 데이터 필터링

분류에서Dev

Python으로 여러 JSON 데이터를 필터링하는 방법은 무엇입니까?

Related 관련 기사

뜨겁다태그

보관