0

我正在按照本教程尝试 DolphinDB 提供的 JSON API 。我尝试了这样的代码片段:

var code = "1+2";
code = encodeURIComponent(code);
paramJson = {
    "sessionID": "942605602",
    "functionName": "executeCode",
    "params": [{
        "name": "script",
        "form": "scalar",
        "type": "string",
        "value": code
    }]
}
var option = {
    url: "http://localhost:9920",
    async: true,
    data: paramJson,
    type: "POST",
    dataType: "json",
    success: function (data) {
        var resultJson = data; 
        console.log(data);
    }
}
$.ajax(option);

这是我从 chrome 获得的日志:

{sessionID: "800870454", userId: "", resultCode: "1", msg: "not a valid json request [sessionID=942605602&func…type%5D=string&params%5B0%5D%5Bvalue%5D=1%252B2].", object: Array(0)}msg: "not a valid json request [sessionID=942605602&functionName=executeCode&params%5B0%5D%5Bname%5D=script&params%5B0%5D%5Bform%5D=scalar&params%5B0%5D%5Btype%5D=string&params%5B0%5D%5Bvalue%5D=1%252B2]."object: []resultCode: "1"sessionID: "800870454"userId: ""__proto__: Object

它报告not a valid json request,但我不知道我的请求有什么问题。

4

1 回答 1

1

您可以在发送请求之前尝试序列化 JSON 对象

data = JSON.stringify(paramJson)
于 2019-06-27T04:56:40.407 回答