2016-10-29 6 views
0

解析に、それぞれの変数にJSONを入れて、それぞれの変数に解析JSONと<strong>RESTのAPI</strong>出力から

を入れて、私はPHPを使用してツールにどの接続して以下のようにJIRAのAPIからの出力を持っていますhttps://github.com/chobie/jira-api-restclient/blob/master/README.mdを使用してください。これは、レコードが非常に細かいフェッチが、私はちょうどそうprint_r($issue['description'])とコードの下に書かれたすべてのレコードからいくつかの情報をしたいが、それは誤りスロー:

私はこれらの3を取得するために$号の代わりに作成する必要がどのような変更

Uncaught Error: Cannot use object of type chobie\Jira\Issue as array

  1. 情報 - [id:protected],[description]および[name]。誰かが私にいくつかのヒントを与えてくれますか?

  2. たとえば、次のようなバグの合計をカウントするにはどうすればよいですか?チョビー\ Jira \問題オブジェクトの数が見つかりましたか?

コード:

$walker = new Walker($api); 
$walker->push(
    'project = "SEA" AND (status != "closed" AND status != "resolved") ORDER BY priority DESC' 
); 

foreach ($walker as $issue) { 
    print "<pre>"; 
    print_r($issue); 
    print "</pre>"; 
} 

だから、$の問題は、以下のようにすべてを印刷しますが、私はちょうど[ID:保護]を取得したい、[説明]および[名前]を。これらの3つの情報を得るために私は$ issueの代わりに何を変える必要がありますか?誰かが私にいくつかのヒントを与えてくれますか?

JSON:

chobie\Jira\Issue Object 
(
    [id:protected] => 21373505 
    [self:protected] => https://test.corp.com/rest/api/2/issue/21373505 
    [key:protected] => S12E-7337 
    [fields:protected] => Array 
    (
     [Status] => Array 
     (
      [self] => https://test.corp.com/rest/api/2/status/3 
      [description] => Working on the issue 
      [iconUrl] => https://test.corp.com/images/icons/statuses/assigned.png 
      [name] => In Progress 
      [id] => 3 
      [statusCategory] => Array 
      (
       [self] => https://test.corp.com/rest/api/2/statuscategory/4 
       [id] => 4 
       [key] => indeterminate 
       [colorName] => yellow 
       [name] => In Progress 
      ) 

     ) 
) 

chobie\Jira\Issue Object 
(
    [id:protected] => 74534233 
    [self:protected] => https://test.corp.com/rest/api/2/issue/74534233 
    [key:protected] => ASE-7327 
    [fields:protected] => Array 
    (
     [Status] => Array 
     (
      [self] => https://test.corp.com/rest/api/2/status/3 
      [description] => This issue is being actively worked on at the moment by the assignee. 
      [iconUrl] => https://test.corp.com/images/icons/statuses/assigned.png 
      [name] => In Progress 
      [id] => 3 
      [statusCategory] => Array 
      (
       [self] => https://test.corp.com/rest/api/2/statuscategory/4 
       [id] => 6 
       [key] => indeterminate 
       [colorName] => yellow 
       [name] => In Progress 
      ) 

     ) 
) 

答えて

0

は答えを得た、あなたは、最初の配列にオブジェクトを変換する配列フィールドを取得し、それに応じてそれを解析する必要があります。

$walker = new Walker($api); 
$walker->push('project = "SEA" AND (status != "closed" AND status != "resolved") ORDER BY priority DESC'); 

foreach ($walker as $issue) { 
    $issue = $bugs->getFields(); 
    print "<pre>"; 
    print_r($issue); 
    print_r(trim($issue['Status']['name']); 
    print "</pre>"; 
} 
関連する問題