Search code examples
jsondatabasedolphindb

Not a valid json request, from DolphinDB JSON API


I'm trying the JSON API provided by DolphinDB, following this tutorial. And I tried the code snippet like this:

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);

Here is the log I got from 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

It report not a valid json request, but I don't know what's wrong with my request.


Solution

  • You can try serializing JSON objects before sending requests

    data = JSON.stringify(paramJson)