douyinghuo8874 2017-09-02 13:57
浏览 781
已采纳

PHP将字符串转换为对象

I have a file that contains the following HL7 Information :

{
  MESSAGE_HEADER: {
    SENDING_APPLICATION: 'IQCARE',
    SENDING_FACILITY: '10829',
    RECEIVING_APPLICATION: 'IL',
    RECEIVING_FACILITY: '10829',
    MESSAGE_DATETIME: '20170713110000',
    SECURITY: '',
    MESSAGE_TYPE: 'ADT^A04',
    PROCESSING_ID: 'P'
  },
  PATIENT_IDENTIFICATION: {
    EXTERNAL_PATIENT_ID: {
      ID: '110ec58a-a0f2-4ac4-8393-c866d813b8d1',
      IDENTIFIER_TYPE: 'GODS_NUMBER',
      ASSIGNING_AUTHORITY: 'MPI'
    }}}

I want to convert this message to a json object and I did the following :

// copy file content into a string var
        $json_file = file_get_contents("" . getcwd() . "\integration_layer\ADT^A04 - Patient Registration.json");
        echo gettype($json_file);
// convert the string to a json object
        $jfo = json_decode($json_file);
// read the title value
        $title = $jfo->MESSAGE_HEADER->SENDING_APPLICATION;
// copy the posts array to a php var
        $posts = $jfo->PATIENT_IDENTIFICATION->EXTERNAL_PATIENT_ID;
// listing posts
        foreach ($posts as $post) {
            echo $post->ID;
        }

But I get the following error :

Severity: Notice

Message: Trying to get property of non-object

When I user the getype function of PHP on the $json_file , it is a string file. How can I convert the message to an object for my own system consumption ?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#网络安全#的问题:非对称加密验证
      • ¥20 关于线性代数里施密特正交化和QR分解的疑问
      • ¥15 matlab超类包含解析错误
      • ¥15 python拖拽文件问题
      • ¥15 执行import paddle代码出现错误如何解决?
      • ¥15 hisat2align exited with value 137
      • ¥15 寻找大学生合作开发软件(Delphi)
      • ¥30 AndroidBench&eMMC内存测试速度&Android
      • ¥15 W10 文件共享失败 怎么解决
      • ¥20 b站私信完整导出的方法