dqwh1218 2014-08-24 04:42
浏览 46

从json获取数据的问题

I have been able to access information from json, but I need more specific information. I need the address. I tried, but it does not show. I can get the name, but when I try to get the address I get no results. Here is the var_dump from json.

    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)

Now I can do this to the name compared to a name that is equal to the name I am looking for.

$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>';


     }
    }
  }
}

When I do this I get no results. Please help.

$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条回答 默认 最新

  • douxuan0698 2014-08-24 04:55
    关注

    Your problem lies here

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

    $item cannot be both

    AuthorizedOfficialFirstName

    as well as

    FirstLineMailingAddress

    So hence why it echos nothing.

    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000