2016-10-26 321 views
0

我有一個json,如下所示。我想訪問adult的值。但是當我做echo json_decode($json_response, true);時,我得到了Array to string conversion。這裏有什麼錯?將json轉換爲數組php將數組轉換爲字符串轉換

{ 
     "responses": [ 
     { 
      "safeSearchAnnotation": { 
      "adult": "VERY_UNLIKELY", 
      "spoof": "VERY_UNLIKELY", 
      "medical": "UNLIKELY", 
      "violence": "LIKELY" 
      } 
     } 
     ] 
    } 

回答

4

函數json_decode返回一個數組。你不能echo一個數組,否則你會得到該轉換錯誤。

你想用print_r代替:

print_r(json_decode($json_response, true)); 

在這裏看到:https://3v4l.org/K3UfP

+0

我真的需要睡覺.... – user2650277

+0

好答案! :) – FluxCoder