1
var request = require('request');
var fs=require("fs");

var program = {
    script :"print('hello\nworld')",
    language: "python3",
    versionIndex: "0",
    clientId: "clientID",
    clientSecret:"clientSecret"
};
request({
    url: 'https://api.jdoodle.com/execute',
    method: "POST",
    json: program
},
function (error, response, body) {
    console.log('error:', error);
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
});

输出:

error: null
statusCode: 200
body: { output: '\njdoodle.c:1:7: warning: missing terminating \' character\n print(\'hello\n       ^\njdoodle.c:1:1: error: missing terminating \' c
haracter\n print(\'hello\n ^\njdoodle.c:2:6: warning: missing terminating \' character\n world\')\n      ^\njdoodle.c:2:1: error: missing terminating
 \' character\n world\')\n ^\njdoodle.c:2:1: error: expected \')\' at end of input\n',
  statusCode: 200,
  memory: null,
  cpuTime: null }

有没有其他方法可以将代码发送到编译器 api 来执行它请建议我 感谢您提前帮助我

4

2 回答 2

0

尝试

script :"print('hello\\nworld')",
于 2018-10-26T07:24:03.397 回答
0

在表单中使用 textArea 来获取代码它会自动将代码更改为 jDoodle 可理解的格式。
仅适用于这里:

script :"print('hello\r\nworld')",
于 2020-11-07T17:58:47.790 回答