这些PHP脚本在读取JSON时有什么问题?

这些PHP脚本在读取JSON时有什么问题?,php,json,Php,Json,这是我写的代码: $result = $textProc->sentiment($text); $json_a = json_decode($result, true); echo $json_a[label]; 其中$result存储JSON数据 但是,它返回错误: Warning: json_decode() expects parameter 1 to be string, object given in C:\xampp \htdocs\ai\sentiment.php on l

这是我写的代码:

$result = $textProc->sentiment($text);
$json_a = json_decode($result, true);
echo $json_a[label];
其中$result存储JSON数据

但是,它返回错误:

Warning: json_decode() expects parameter 1 to be string, object given in C:\xampp
\htdocs\ai\sentiment.php on line 9

Notice: Use of undefined constant label - assumed 'label' in C:\xampp\htdocs
\ai\sentiment.php on line 11
解决方案: 这是var_dump($result)的输出:


抱歉,我应该先检查此项。

$result不是字符串。使用
print\r($result)
$result不是字符串,尝试找出字符串在对象中的存储位置。尝试使用
print\r($result)
找出字符串在对象中的存储位置

注意:使用未定义的常量标签-在 第11行的C:\xampp\htdocs\ai\touction.php

echo$json_a[label]上标签指的是一个不存在的常数

要引用关联数组中的元素,必须按照以下步骤执行

echo $json_a['label'];

警告:json_decode()要求参数1为字符串,对象为给定值 在第9行的C:\xampp\htdocs\ai\touction.php中

接下来,在
$result=$textProc->情绪($text),函数不返回字符串。执行
var\u dump($result)
以确保它返回的是jsonstring格式

注意:使用未定义的常量标签-在 第11行的C:\xampp\htdocs\ai\touction.php

echo$json_a[label]上标签指的是一个不存在的常数

要引用关联数组中的元素,必须按照以下步骤执行

echo $json_a['label'];

警告:json_decode()要求参数1为字符串,对象为给定值 在第9行的C:\xampp\htdocs\ai\touction.php中


接下来,在
$result=$textProc->情绪($text),函数不返回字符串。执行
var\u dump($result)
以确保返回jsonstring格式。

如何声明$result?发布
var\u dump($result)的输出尝试
var\u dump($result)
并查看它返回什么。您可以将其转换为字符串。如何声明$result?发布
var\u dump($result)的输出尝试
var\u dump($result)
并查看它返回什么。您可能只需要将其转换为字符串。