Converting the javascript object to json object

This question already has an answer here:

  • Serializing to JSON in jQuery [duplicate] 11 answers

  • logMessage = function (msg, severity, vendorId, userName, actionPerformed, priority, traceId, dataSent) {
        this.message = msg;
        this.severity = severity;
        this.vendorId = vendorId;
        this.userName = userName;
        this.actionPerformed = actionPerformed;
        this.priority = priority;
        this.traceId = traceId;
        this.dataSent = dataSent;
    };
    
    var msg = new logMessage(err, "High", "none", qry.username, "Error on login call: /req/login", "high", "", qry);
    Utility.writeToLoggly(JSON.stringify(msg));
    

    你可以使用JSON.stringify()函数,所以只需添加到你的代码中:

    Utility.writeToLoggly(JSON.stringify(msg));
    
    链接地址: http://www.djcxy.com/p/8090.html

    上一篇: 如何访问JSON对象中的值?

    下一篇: 将JavaScript对象转换为json对象