从json获取数据的问题

时间:2014-08-24 04:42:03

标签: php json

我能够从json访问信息,但我需要更具体的信息。我需要地址。我试过了,但没有表现出来。我可以得到这个名字,但是当我试图获得地址时,我得不到任何结果。 这是来自json的var_dump。

    array (size=1)
  'NPI' => 
    array (size=30)
      0 => 
        array (size=35)
          'NPI' => string '1720071798' (length=10)
          'EntityType' => string 'Individual' (length=10)
          'IsSoleProprietor' => string 'X' (length=1)
          'LastName' => string 'BURGESS-PETERSON' (length=16)
          'FirstName' => string 'HEATHER' (length=7)
          'MiddleName' => string 'MARIE' (length=5)
          'NamePrefix' => string 'DR.' (length=3)
          'Credential' => string 'O.D.' (length=4)
          'FirstLineMailingAddress' => string '15780 RIDGE LN' (length=14)
          'MailingAddressCityName' => string 'SPRING LAKE' (length=11)
          'MailingAddressStateName' => string 'MI' (length=2)
          'MailingAddressPostalCode' => string '49456-1557' (length=10)
          'MailingAddressCountryCode' => string 'US' (length=2)
          'MailingAddressTelephoneNumber' => string '231-719-9200' (length=12)
          'MailingAddressFaxNumber' => string '231-744-6782' (length=12)
          'FirstLinePracticeLocationAddress' => string '1871 HOLTON RD' (length=14)
          'SecondLinePracticeLocationAddress' => string 'SUITE A' (length=7)
          'PracticeLocationAddressCityName' => string 'MUSKEGON' (length=8)
          'PracticeLocationAddressStateName' => string 'MI' (length=2)
          'PracticeLocationAddressPostalCode' => string '49445-1594' (length=10)
          'PracticeLocationAddressCountryCode' => string 'US' (length=2)
          'PracticeLocationAddressTelephoneNumber' => string '231-719-9200' (length=12)
          'PracticeLocationAddressFaxNumber' => string '231-744-6782' (length=12)
          'EnumerationDate' => string '08/25/2005' (length=10)
          'LastUpdateDate' => string '07/08/2007' (length=10)
          'GenderCode' => string 'F' (length=1)
          'Gender' => string 'Female' (length=6)
          'TaxonomyCode1' => string '152W00000X' (length=10)
          'Taxonomy1' => string 'Optometrist' (length=11)
          'LicenseNumber1' => string '4901003806' (length=10)
          'LicenseNumberStateCode1' => string 'MI' (length=2)
          'PrimaryTaxonomySwitch1' => string 'Y' (length=1)
          'OtherIdentifier1' => string 'U68516' (length=6)
          'OtherIdentifierType1' => string 'MEDICARE UPIN' (length=13)
          'OtherIdentifierState1' => string 'MI' (length=2)
      1 => 
        array (size=32)
          'NPI' => string '1588640304' (length=10)
          'EntityType' => string 'Individual' (length=10)
          'IsSoleProprietor' => string 'X' (length=1)
          'LastName' => string 'PETERSON' (length=8)
          'FirstName' => string 'HEATHER' (length=7)
          'MiddleName' => string 'ALYSA' (length=5)
          'Credential' => string 'MS SLP LLL' (length=10)
          'FirstLineMailingAddress' => string '1824 BELMONT RD NW' (length=18)
          'SecondLineMailingAddress' => string '#31' (length=3)
          'MailingAddressCityName' => string 'WASHINGTON' (length=10)
          'MailingAddressStateName' => string 'DC' (length=2)
          'MailingAddressPostalCode' => string '20009' (length=5)
          'MailingAddressCountryCode' => string 'US' (length=2)
          'MailingAddressTelephoneNumber' => string '202-425-6874' (length=12)
          'MailingAddressFaxNumber' => string '703-922-0638' (length=12)
          'FirstLinePracticeLocationAddress' => string '6506 LOISDALE RD' (length=16)
          'SecondLinePracticeLocationAddress' => string 'SUITE #300' (length=10)
          'PracticeLocationAddressCityName' => string 'SPRINGFIELD' (length=11)
          'PracticeLocationAddressStateName' => string 'VA' (length=2)
          'PracticeLocationAddressPostalCode' => string '22150' (length=5)
          'PracticeLocationAddressCountryCode' => string 'US' (length=2)
          'PracticeLocationAddressTelephoneNumber' => string '703-924-4183' (length=12)
          'PracticeLocationAddressFaxNumber' => string '703-922-0638' (length=12)
          'EnumerationDate' => string '12/22/2005' (length=10)
          'LastUpdateDate' => string '07/08/2007' (length=10)
          'GenderCode' => string 'F' (length=1)
          'Gender' => string 'Female' (length=6)
          'TaxonomyCode1' => string '235Z00000X' (length=10)
          'Taxonomy1' => string 'Speech-Language Pathologist' (length=27)
          'LicenseNumber1' => string '12074933' (length=8)
          'LicenseNumberStateCode1' => string 'VA' (length=2)
          'PrimaryTaxonomySwitch1' => string 'Y' (length=1)
      2 => 
        array (size=30)
          'NPI' => string '1861583460' (length=10)
          'EntityType' => string 'Individual' (length=10)
          'IsSoleProprietor' => string 'N' (length=1)
          'LastName' => string 'PETERSON' (length=8)
          'FirstName' => string 'HEATHER' (length=7)
          'MiddleName' => string 'M' (length=1)
          'Credential' => string 'RN' (length=2)
          'FirstLineMailingAddress' => string '2575 N COURTENAY PKWY' (length=21)
          'MailingAddressCityName' => string 'MERRITT ISLAND' (length=14)
          'MailingAddressStateName' => string 'FL' (length=2)
          'MailingAddressPostalCode' => string '32953' (length=5)
          'MailingAddressCountryCode' => string 'US' (length=2)
          'MailingAddressTelephoneNumber' => string '321-639-5787' (length=12)
          'MailingAddressFaxNumber' => string '321-639-5762' (length=12)
          'FirstLinePracticeLocationAddress' => string '2575 N COURTENAY PKWY' (length=21)
          'PracticeLocationAddressCityName' => string 'MERRITT ISLAND' (length=14)
          'PracticeLocationAddressStateName' => string 'FL' (length=2)
          'PracticeLocationAddressPostalCode' => string '32953' (length=5)
          'PracticeLocationAddressCountryCode' => string 'US' (length=2)
          'PracticeLocationAddressTelephoneNumber' => string '321-639-5787' (length=12)
          'PracticeLocationAddressFaxNumber' => string '321-639-5762' (length=12)
          'EnumerationDate' => string '09/27/2006' (length=10)
          'LastUpdateDate' => string '07/08/2007' (length=10)
          'GenderCode' => string 'F' (length=1)
          'Gender' => string 'Female' (length=6)
          'TaxonomyCode1' => string '163WS0200X' (length=10)
          'Taxonomy1' => string 'School' (length=6)
          'LicenseNumber1' => string 'RN9203188' (length=9)
          'LicenseNumberStateCode1' => string 'FL' (length=2)
          'PrimaryTaxonomySwitch1' => string 'Y' (length=1)

现在,我可以将此名称与名称相对于我正在寻找的名称进行比较。

$json = json_decode($data,true);
$firstName = strtoupper($firstName);
$lastName = strtoupper($lastName);
var_dump($json);
foreach($json['NPI'] as $key => $val){
//echo $key .'=>'. $val.'<br>';
foreach($val as $item => $info){
    //echo $item .'=>'.$data.'<br>';
    if($item == 'AuthorizedOfficialFirstName' && $info == $firstName){

        echo $firstName.' '.$lastName.'<br>';


     }
    }
  }
}

当我这样做时,我没有得到任何结果。请帮忙。

$json = json_decode($data,true);
$firstName = strtoupper($firstName);
$lastName = strtoupper($lastName);
var_dump($json);
 foreach($json['NPI'] as $key => $val){
//echo $key .'=>'. $val.'<br>';
foreach($val as $item => $info){
    //echo $item .'=>'.$data.'<br>';
    if($item == 'AuthorizedOfficialFirstName' && $info == $firstName){
        if($item == 'FirstLineMailingAddress'){
        echo $firstName.' '.$lastName.'<br>';
        echo $info.'<br>';
        //echo $json['NPI']['FirstLinePracticeLocationAddress'];
     }
    }
   }
}

1 个答案:

答案 0 :(得分:1)

你的问题就在这里

if($item == 'AuthorizedOfficialFirstName' && $info == $firstName){
    if($item == 'FirstLineMailingAddress'){

$ item不能同时

  

AuthorizedOfficialFirstName

以及

  

FirstLineMailingAddress

因此,为什么它没有回声。