function Map() {
var struct = function(key, value) {
this.key = key;
this.value = value;
};
var put = function(key, value){
for (var i = 0; i < this.arr.length; i++) {
if ( this.arr[i].key === key ) {
this.arr[i].value = value;
return;
}
}
this.arr[this.arr.length] = new struct(key, value);
};
var get = function(key) {
for (var i = 0; i < this.arr.length; i++) {
if ( this.arr[i].key === key ) {
return this.arr[i].value;
}
}
return null;
};
var remove = function(key) {
var v;
for (var i = 0; i < this.arr.length; i++) {
v = this.arr.pop();
if ( v.key === key ) {
continue;
}
this.arr.unshift(v);
}
};
var size = function() {
return this.arr.length;
};
var isEmpty = function() {
return this.arr.length <= 0;
};
var getVTMSendStr=function() {
var vtmStr="";
for (var i = 0; i < this.arr.length; i++) {
vtmStr=(i+1!=this.arr.length) ? (vtmStr+this.arr[i].key+"="+this.arr[i].value+"|"):(vtmStr+this.arr[i].key+"="+this.arr[i].value);
}
return vtmStr;
};
var getVTASendStr=function() {
var vtaStr="{";
for (var i = 0; i < this.arr.length; i++) {
vtaStr=(i+1!=this.arr.length) ? (vtaStr+"\""+this.arr[i].key+"\":\""+this.arr[i].value+"\",") : (vtaStr+"\""+this.arr[i].key+"\":\""+this.arr[i].value+"\"}");
}
if(0 == this.arr.length){
vtaStr="{}";
}
return vtaStr;
};
this.arr = new Array();
this.get = get;
this.put = put;
this.remove = remove;
this.size = size;
this.isEmpty = isEmpty;
this.getVTMSendStr=getVTMSendStr;
this.getVTASendStr=getVTASendStr;
}
var dataMap = new Map();
dataMap.put("keyName",value);
dataMap.get("keyName");
dataMap.getVTMSendStr();//格式化为Json串:{keyName=value|keyName=value|keyName=value|keyName=value}
dataMap.getVTASendStr();//格式化为Json串:{keyName:value|keyName:value|keyName:value|keyName=value}
dataMap.remove("keyName");
dataMap.isEmpty();//判空