如何在var中获取RESUMEID值

时间:2013-11-18 14:41:44

标签: php

我正在尝试通过JSON Api获取一些特定数据,并访问“RESUMEID”的结果。

为此,我从内容中获取文件,并对json进行编码。

$url = '####';

$JSON = file_get_contents($url);
$data = json_decode($JSON);
var_dump($data);

当我转储数据时,它已经相当多了,而且我不太确定如何专门获取“RESUMEID”变量。

以下是数据的外观 - >

{
"response":{
      "result":{
         "Candidates":{
            "row":{
               "no":"1",
               "FL":[
                  {
                     "content":"208468000000171001",
                     "val":"RESUMEID"
                  },
                  {
                     "content":"Not specified",
                     "val":"Modified by"
                  },
                  {
                     "content":"Yesterday",
                     "val":"Modified time"
                  },
                  {
                     "content":"284",
                     "val":"Candidate ID"
                  },
                  {
                     "content":"Scott",
                     "val":"First name"
                  },
                  {
                     "content":"Example First Name",
                     "val":"Last name"
                  },
                  {
                     "content":"exampleemail@gmail.com",
                     "val":"Email ID"
                  },
                  {
                     "content":"Beijing",
                     "val":"Current City"
                  },
                  {
                     "content":"Yesterday",
                     "val":"Created On"
                  },
                  {
                     "content":"Embed",
                     "val":"Source"
                  },
                  {
                     "content":"Intermediate",
                     "val":"Read/Type"
                  },
                  {
                     "content":"Conversational",
                     "val":"Listen/Speak"
                  },
                  {
                     "content":"_Resume.doc",
                     "val":"Attach resume",
                     "type":"url",
                     "url":"http://sdsLkRIyw--"
                  },
                  {
                     "content":"New",
                     "val":"Resume status"
                  },
                  {
                     "content":"2 years",
                     "val":"Time in China"
                  },
                  {
                     "content":"-----",
                     "val":"Tell us more about your professional interests in joining ATLAS-China and career goals"
                  },
                  {
                     "content":"2011",
                     "val":"Graduation year (undergraduate)"
                  },
                  {
                     "content":"Marketing",
                     "val":"Desired Industry or ATLAS Role"
                  },
                  {
                     "content":"Beijing",
                     "val":"Location Preference"
                  },
                  {
                     "content":"Yes, "Branding and Digital Marketing Junior Strategist"",
                     "val":"Is this in reference to a particular job?"
                  },
                  {
                     "content":"10,000RMB/month (flexible)",
                     "val":"Salary Range"
                  }
               ]
            }
         }
      },
      "uri":"/ats/private/json/Candidates/getRecords"
   }
}

我尝试通过调用添加此项来获取RESUMEID - >

$id = $data->response->result->RESUMEID;

但我一无所获。看看上面的var_dump,你会写什么来专门获取RESUMEID的内容?

2 个答案:

答案 0 :(得分:0)

您可以使用echo '<pre>'.print_r($data, true).'</pre>获取JSON对象的结构化输出。

树看起来像:

stdClass Object
(
    [response] => stdClass Object
        (
            [result] => stdClass Object
                (
                    [Candidates] => stdClass Object
                        (
                            [row] => stdClass Object
                                (
                                    [no] => 1
                                    [FL] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [content] => 208XXX
                                                    [val] => RESUMEID
                                                )

要检索RESUMEID文字,您可以执行以下操作:

$id = $data->response->result->Candidates->row->FL[0]->val;

如果您正在尝试检索ID(从208开始),那么您可以执行以下操作:

$id = $data->response->result->Candidates->row->FL[0]->val;

Demo!

答案 1 :(得分:0)

您必须filter $data -> response -> result -> Candidates -> row -> FL这样的数组:

$result = array_filter($data -> response -> result -> Candidates -> row -> FL, function($item){
  return $item -> val === 'RESUMED';
});

echo $result -> content;