簡體   English   中英

php,從json返回特定的對象值並將其分配給變量

[英]php, return a specific object value from json and assign it to variable

如何在PHP腳本中將client_id分配給變量?

{
      "success": true,
      "client_id": "14",
      "call": "addClient",
      "server_time": 1323785423,
      "info": [
         "New client account created"
      ]
   }

如何在PHP腳本中將client_id分配給變量?

以下是我用於生成上述json輸出的命令。

  $return = HBWrapper::singleton()->addClient($params);

我在foreach循環中使用return。

  foreach ($return as $id) { 
    echo $id->client_id;
}

問題是您試圖直接訪問字符串而不進行轉換,可以使用json_decode($string)實現將其引用為對象

$return = json_decode(HBWrapper::singleton()->addClient($params));

foreach ($return as $id) { 
    echo $id->client_id;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM