{"id":"132","object":"chat.completion","created":1685194451,"result":"abc","need_clear_history":false,"usage":{"prompt_tokens":13,"completion_tokens":316,"total_tokens":329}} 用php取total_tokens值
时间: 2023-06-29 22:16:25 浏览: 204
可以使用以下代码来获取这个 JSON 字符串中的 `total_tokens` 值:
```php
$json_str = '{"id":"132","object":"chat.completion","created":1685194451,"result":"abc","need_clear_history":false,"usage":{"prompt_tokens":13,"completion_tokens":316,"total_tokens":329}}';
$data = json_decode($json_str, true);
$total_tokens = $data['usage']['total_tokens'];
echo $total_tokens;
```
输出结果为:
```
329
```
阅读全文
相关推荐

















