这适用于适用于PHP的AWS LexRuntimeService SDK 当Lex使用任何ElicitIntent响应响应SDK时,这是我继续得到的完整错误:
ParserException:解析JSON时出错:第20行的... / Aws / Api / Parser / PayloadParserTrait.php中的语法错误
ElicitSlot不会导致此异常错误。
我无法找到一种方法来查看正在解析的JSON对象或字符串并导致错误 但是,当我使用Lex测试聊天机器人,并触发与应该返回到SDK的响应相同的响应时,我注意到工作的意图和导致此错误的其他意图之间的JSON差异在IntentName中为空领域。但是,当我尝试向ElicitIntent提供intentName时,Lex bot会在接收到intentName时出错。所以lex为ElicitIntent指令输出null intentName。
见这里:
使用input =“预订乘车”启动BookRide Intent Lex JSON Response =
{
"dialogState": "ElicitSlot",
"intentName": "BookRide",
"message": "Hi. Where are you going?",
"messageFormat": "PlainText",
"responseCard": null,
"sessionAttributes": {},
"slotToElicit": "address",
"slots": null
}
SDK RESULT = PASS。没有错误。
触发其他意图:输入=“你好”,“谢谢”,“帮助”
(其他意图都触发ElicitIntent,但有不同的消息)
Lex JSON Response =
{
"dialogState": "ElicitIntent",
"intentName": null,
"message": "Hello. I can help you order a ride. Just ask, book me a ride, to get started.",
"messageFormat": "PlainText",
"responseCard": null,
"sessionAttributes": {},
"slotToElicit": null,
"slots": null
}
SDK RESULT =错误:ParserException: Error parsing JSON: Syntax error
这是使用PostContent将消息传递给我的Lex机器人的代码。
$credentials = new \Aws\Credentials\Credentials('XXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXX');
$args = array(
'region' => 'us-east-1',
'version' => 'latest',
'debug' => true,
'credentials' => $credentials
);
$lex_client = new Aws\LexRuntimeService\LexRuntimeServiceClient($args);
$lex_response = $lex_client->postContent([
'accept' => 'text/plain; charset=utf-8',
'botAlias' => 'XXXX',
'botName' => 'XXXX',
'contentType' => 'text/plain; charset=utf-8',
'inputStream' => $userInput,
'requestAttributes' => array(),
'sessionAttributes' => array(),
'userId' => 'XXXXXXXXXXXX',
]);
是什么导致ParseException的想法?
或者我如何查看导致抛出ParseException的原因的详细信息?
更新:
这不能解决问题,但只是尝试使用postText
代替postContent
和ElicitIntent
指令正常工作!
因此,此错误仅限于SDK中的postContent
。