【发布时间】:2014-04-29 10:45:22
【问题描述】:
我正在尝试在服务器端使用 jansson lib 形成 JSON 响应 下面是代码sn-p,用于构建对客户端请求的JSON响应(用js编写)
json_object_set(root,"response",msgType);
json_object_set_new(msgType,"reqID",json_string(reqId));
json_object_set_new(msgType,"method",json_string(metName));
json_object_set_new(msgType,"speakID",json_string(reqId));
json_object_set_new(msgType,"numSegments",json_integer(1));
char * jsonStringResponse = json_dumps(root, 0 );
mg_websocket_write(connecion, 1, jsonStringResponse, strlen(jsonStringResponse));
在变量 jsonStringResponse 中形成这个
{"response":{"method":"Speak","reqID":"30","speakID":"30","numSegments":"1"}}
现在在客户端实现中,这是验证它的方式,我未能通过此验证。
// test the Speak method
it('Speak', function(done) {
var id = "123";
var method = "Speak";
WsTestBase.send({
"request":
{
"method": method,
"reqID": id,
"parameters":
{
"text" : ttsText
}
}
});
WsTestBase.validate({
"method": method,
"reqID":id,
"speakID":id,
"numSegments":1
},[
{ eventName : 'SpeechEnd', speakID : id }
], done);
});
请告诉我如何发送预期的eventName,而我的回复正文中缺少该eventName?
【问题讨论】:
标签: javascript json websocket jasmine dom-events