2017-06-07 14 views
-1

我有一個從get_post_meta生成的數據,我需要將其轉換爲JSON。所產生的陣列如下:get_post_meta()到JSON

Array 
(
    [0] => Array 
     (
      [0] => Array 
       (
        [0] => Array 
         (
          [rate] => 5 
          [review] => Array 
           (
            [content] => Test Review 
            [custom_field_1] => Azman Ishak 
            [custom_field_2] => Selagnor 
            [date] => 2017-06-06 , 15:06 
            [title] => 
            [status] => publish 
            [weight] => 5 
           ) 

          [user] => Array 
           (
            [name] => ebeneadmin 
            [email] => [email protected] 
            [id] => 1 
            [ip] => 115.135.10.5 
           ) 

         ) 

       ) 

     ) 

    [1] => Array 
     (
      [0] => Array 
       (
        [0] => Array 
         (
          [rate] => 4 
          [review] => Array 
           (
            [content] => Test review 2 
            [custom_field_1] => Azman 
            [custom_field_2] => Beranang 
            [date] => 2017-06-06 , 16:01 
            [title] => 
            [status] => publish 
            [weight] => 5 
           ) 

          [user] => Array 
           (
            [name] => Azman Ishak 
            [email] => [email protected] 
            [id] => 
            [ip] => 115.135.10.5 
           ) 

         ) 

       ) 

     ) 

    [2] => Array 
     (
      [0] => Array 
       (
       ) 

     ) 

) 

,我需要從上述陣列得到的值是:

  1. 內容
  2. CUSTOM_FIELD_1
  3. CUSTOM_FIELD_2
  4. 日期
  5. 標題
  6. 狀態

需要將此數據轉換爲JSON。

+1

您好,歡迎SO。我們在這裏幫助您解決特定的編程問題,而不是爲您編寫代碼。所以,既然你已經堅持了兩天,告訴我們你到目前爲止所做的嘗試,與我們分享你的想法,我相信你會得到幫助。這樣你就可以從錯誤中學習,而且你不會做簡單的複製+粘貼。 – Twinfriends

回答

0

試試這個:

轉換您get_post_meta與json_encode();

導致它會讓你的結果是

<?php 
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); 

echo json_encode($arr); 
?> 

輸出:

{"a":1,"b":2,"c":3,"d":4,"e":5}