将JavaScript对象转换为json对象

这个问题在这里已经有了答案:

  • 在jQuery中序列化为JSON [复制] 11个回答

  • 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/8089.html

    上一篇: Converting the javascript object to json object

    下一篇: Serializing to JSON in jQuery