【问题标题】:When I try to send code as string to jdoodle compiler api I am getting errors当我尝试将代码作为字符串发送到 jdoodle 编译器 api 时出现错误
【发布时间】:2018-06-18 09:07:33
【问题描述】:
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 来执行它,请给我建议 感谢您提前帮助我

【问题讨论】:

    标签: node.js compiler-errors online-compilation jdoodle


    【解决方案1】:

    试试

    script :"print('hello\\nworld')",
    

    【讨论】:

      【解决方案2】:

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

      script :"print('hello\r\nworld')",
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多