您需要做的第一件事是使用与 BO 同名的 require 数据类型来制作 BO。然后使用以下代码将 twObject 转换为 JSON:-
function createJson(twObject){
var jsonString="";
if(typeof twObject =='object' && twObject!=null){
if(twObject.listLength>0){
jsonString+="[";
for (var j=0; j<twObject.listLength; j++){
if(typeof twObject[j]!='string')
jsonString+="{";
for (var property in twObject[j].propertyNames){
var name = twObject[j].propertyNames[property];
if(typeof twObject[j][name]=='object'){
if(Object.prototype.toString.call(twObject[j][name]).indexOf("TWDate")!="-1"){
jsonString+="\""+name+"\":\""+twObject[j][name].format("yyyy-MM-dd'T'HH:mm:ss'Z'")+"\",";
}else{
jsonString+="\""+name+"\":"+createJson(twObject[j][name]);
}
}
else{
jsonString+="\""+name+"\":\""+twObject[j][name]+"\",";
}
if(twObject[j].listLength>0)
{
for (var k=0;k<twObject[j].listLength;k++){
jsonString+="\""+ twObject[j][k]+"\",";
}
}
}
if(typeof twObject[j] == 'string'){
jsonString+="\""+twObject[j]+"\"";
}
if(typeof twObject[j]!='string')
jsonString+="}";
if(j!=twObject.listLength-1){
jsonString+=",";
}
} jsonString+="],";
}else{
try{
if(twObject.propertyNames.length>0){
jsonString+="{";
for(var property in twObject.propertyNames){
var name = twObject.propertyNames[property];
if(typeof twObject[name]=='object'){
if(Object.prototype.toString.call(twObject[name]).indexOf("TWDate")!="-1"){
jsonString+="\""+name+"\":\""+twObject[name].format("yyyy-MM-dd'T'HH:mm:ss'Z'")+"\",";
}else{
jsonString+="\""+name+"\":"+createJson(twObject[name]);
}
}else{
jsonString+="\""+name+"\":\""+twObject[name]+"\",";
}
}
jsonString+="},"; }
else{
return "{},";
}}catch(e){
return "{},";
}
}
}
else if(typeof twObject =='object' && twObject==null){
return "{},";
}
return jsonString;
}
源代码:http ://www.ibpmcoding.com 。