2016-05-24 32 views
-2

Ich möchte versuchen, Json Datenwert von URL mit PHP-Skript zu bekommen.Wie zu dekodieren JSON-Datei von URL mit PHP

$method = $_SERVER['REQUEST_METHOD']; 
    $request = explode('/', trim($_SERVER['PATH_INFO'],'/')); 
    $input = json_decode(file_get_contents('http://username:[email protected]/openbravo/org.openbravo.service.json.jsonrest/THR_App_Rcrt_Type'),true); 
    foreach ($input as $key => $value){ 
     echo "$key: $value\n"; 
}; 

Die JSON:

{ 
    "response": { 
     "data": [{ 
      "_identifier": "HR Executive", 
      "_entityName": "THR_App_Rcrt_Type", 
      "$ref": "THR_App_Rcrt_Type\/E9228AAE023F4E699BB1B2C9813A9B22", 
      "id": "E9228AAE023F4E699BB1B2C9813A9B22", 
      "organization": "F3B1FD7FA8094DEEB3ECF29C0FCA06AE", 
      "organization$_identifier": "Khayal Al Wataniya Company", 
      "client": "620768B8D9E54D919A11CCBFB129C24F", 
      "client$_identifier": "Khayal Al Wataniya Holding Com", 
      "active": true, 
      "creationDate": "2014-12-04T06:54:24+01:00", 
      "createdBy": "EF07CFDC719B4A07AB129FE2F9F45A24", 
      "createdBy$_identifier": "ADNAN SAEED MOHAMMED SABAGH - ", 
      "updated": "2014-12-04T06:54:24+01:00", 
      "updatedBy": "EF07CFDC719B4A07AB129FE2F9F45A24", 
      "updatedBy$_identifier": "ADNAN SAEED MOHAMMED SABAGH - ", 
      "recruitmentType": "Employment agencies", 
      "recruitmentInfo": "HR Executive", 
      "recordTime": 1464067361833 
     }, { 
      "_identifier": "HR", 
      "_entityName": "THR_App_Rcrt_Type", 
      "$ref": "THR_App_Rcrt_Type\/22203768C310447CB516258B246B92E5", 
      "id": "22203768C310447CB516258B246B92E5", 
      "organization": "F3B1FD7FA8094DEEB3ECF29C0FCA06AE", 
      "organization$_identifier": "Khayal Al Wataniya Company", 
      "client": "620768B8D9E54D919A11CCBFB129C24F", 
      "client$_identifier": "Khayal Al Wataniya Holding Com", 
      "active": true, 
      "creationDate": "2014-12-06T07:08:41+01:00", 
      "createdBy": "B2CED8798FE3490AAFFEE2301FC8DC53", 
      "createdBy$_identifier": "Mohammed - ", 
      "updated": "2014-12-06T07:08:41+01:00", 
      "updatedBy": "B2CED8798FE3490AAFFEE2301FC8DC53", 
      "updatedBy$_identifier": "Mohammed - ", 
      "recruitmentType": "Outsourcing", 
      "recruitmentInfo": "HR", 
      "recordTime": 1464067361836 
     }, { 
      "_identifier": "..!!", 
      "_entityName": "THR_App_Rcrt_Type", 
      "$ref": "THR_App_Rcrt_Type\/0004F2A85CB54F199D50041F5FFFEA16", 
      "id": "0004F2A85CB54F199D50041F5FFFEA16", 
      "organization": "F3B1FD7FA8094DEEB3ECF29C0FCA06AE", 
      "organization$_identifier": "Khayal Al Wataniya Company", 
      "client": "620768B8D9E54D919A11CCBFB129C24F", 
      "client$_identifier": "Khayal Al Wataniya Holding Com", 
      "active": true, 
      "creationDate": "2015-02-11T12:44:33+01:00", 
      "createdBy": "22842EF590924083B472EFE588BA98C3", 
      "createdBy$_identifier": "Fatemah Saleh Batterjee - ", 
      "updated": "2015-02-11T12:44:33+01:00", 
      "updatedBy": "22842EF590924083B472EFE588BA98C3", 
      "updatedBy$_identifier": "Fatemah Saleh Batterjee - ", 
      "recruitmentType": "Employment agencies", 
      "recruitmentInfo": "..!!", 
      "recordTime": 1464067361839 
     }], 
     "status": 0, 
     "totalRows": 3, 
     "startRow": 0, 
     "endRow": 2 
    } 
} 

Wie bekomme ich einen Wert aus es mit PHP?

+1

'file_get_content' und' json_decode ($ file_content) 'und es für Werte foreach ......... –

+0

Dieser Code hat bereits die innerhalb – Dale

+0

enthaltenen Antwort das Ergebnis auf gezeigt "Antwort: Array" . aber ich brauche Datenwert. –

Antwort

0
<?php 
$method = $_SERVER['REQUEST_METHOD']; 
$request = explode('/', trim($_SERVER['PATH_INFO'],'/')); 
$json = json_decode(file_get_contents('http://username:[email protected]/openbravo/org.openbravo.service.json.jsonrest/THR_App_Jb_Pst_Dtl'),true); 


foreach ($json as $input =>$response){ 
    //echo $input; 
    //echo $response; 
foreach ($response as $response_array_name=> $response_value) { 
    //echo $response_array_name . "\n" . "<br>"; 
    //echo $response_value . "\n" . "<br>"; 
     foreach ($response_value as $data_array => $data_value) { 
      //echo $data_array . "\n" . "<br>"; 
      //echo $data_value . "\n" . "<br>"; 
       foreach ($data_value as $data_array_name => $data_array_value) { 
        if ($data_array_name=='_identifier') { 
         echo $data_array_name ." :". $data_array_value . "\n" . "<br>"; 
        } 

        //echo $data_array_name . "\n" . "<br>"; 
        //echo $data_array_value . "\n" . "<br>"; 
      } 
     } 
} 
    }; 
?>