??????????
????????????????????????????????main.js???????????£?
var http = require("http");
function onRequest(request?? response){
console.log("Request received.");
var str='{"id":"0036"??name:"jack"??arg:123}';
response.writeHead(200??{"Content-Type":'text/plain'??'charset':'utf-8'??'Access-Control-Allow-Origin':'*'??'Access-Control-Allow-Methods':'PUT??POST??GET??DELETE??OPTIONS'});
//response.writeHead(200??{"Content-Type":'application/json'??'Access-Control-Allow-Origin':'*'??'Access-Control-Allow-Methods':'PUT??POST??GET??DELETE??OPTIONS'});
//response.write("Hello World 8888 ");
response.write(str);
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.port on 8888");
???????з?????????????У????????node main.js??????IE?????????http://127.0.0.1:8888???????????????????
????======================================================================
???????????
??????????json?????????json?????????????????????????json.js??
var http = require("http");
var fs = require("fs");
var str='{"id":"123"??name:"jack"??arg:11111}';
function onRequest(request?? response){
console.log("Request received.");
response.writeHead(200??{"Content-Type":'text/plain'??'charset':'utf-8'??'Access-Control-Allow-Origin':'*'??'Access-Control-Allow-Methods':'PUT??POST??GET??DELETE??OPTIONS'});//???????????????
//response.writeHead(200??{"Content-Type":'application/json'??            'Access-Control-Allow-Origin':'*'??'Access-Control-Allow-Methods':'PUT??POST??GET??DELETE??OPTIONS'});
//response.write("Hello World 8888 ");
str=fs.readFileSync('data.txt');
response.write(str);
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.port on 8888 ");
console.log("test data: "+str.toString());
???????????????±??????data.txt????????????
????{"id":"0036"??name:"jack"??arg:32100??
????remark:"test data"}
???????з?????????????У????????node json.js??????IE?????????http://127.0.0.1:8888???????????????????
????======================================================================
???????????
??????дini????????????ini????????????£??????ini.js???
var eol = process.platform === "win32" ? " " : " "
function INI() {
this.sections = {};
}
/**
* ???Section
* @param sectionName
*/
INI.prototype.removeSection = function (sectionName) {
sectionName =  sectionName.replace(/[/g??'(');
sectionName = sectionName.replace(/]/g??')');
if (this.sections[sectionName]) {
delete this.sections[sectionName];
}
}
/**
* ?????????????Section
* @type {Function}
*/
INI.prototype.getOrCreateSection = INI.prototype.section = function (sectionName) {
sectionName =  sectionName.replace(/[/g??'(');
sectionName = sectionName.replace(/]/g??')');
if (!this.sections[sectionName]) {
this.sections[sectionName] = {};
}
return this.sections[sectionName]
}
/**
* ??INI????????
*
* @returns {string}
*/
INI.prototype.encodeToIni = INI.prototype.toString = function encodeIni() {
var _INI = this;
var sectionOut = _INI.encodeSection(null?? _INI);
Object.keys(_INI.sections).forEach(function (k?? _?? __) {
if (_INI.sections) {
sectionOut += _INI.encodeSection(k?? _INI.sections[k])
}
});
return sectionOut;
}
/**
*
* @param section
* @param obj
* @returns {string}
*/
INI.prototype.encodeSection = function (section?? obj) {
var out = "";
Object.keys(obj).forEach(function (k?? _?? __) {
var val = obj[k];
if(k=="___comment")return;
if (val && Array.isArray(val)) {
val.forEach(function (item) {
out += safe(k + "[]") + " = " + safe(item) + " "
})
} else if (val && typeof val === "object") {
} else {
out += safe(k) + " = " + safe(val) + eol
}
})
if (section && out.length) {
out = "[" + safe(section) + "]" + eol + out
}
if (section || obj.___comment){
out = obj.___comment + eol + out;
}
return out+" ";
}
function safe(val) {
return (typeof val !== "string" || val.match(/[ ]/) || val.match(/^[/) || (val.length > 1 && val.charAt(0) === """ && val.slice(-1) === """) || val !== val.trim()) ? JSON.stringify(val) : val.replace(/;/g?? '\;')
}
var regex1 = {
section: /^s*[s*([^]]*)s*]s*$/??
param: /^s*([w.-\_@]+)s*=s*(.*?)s*$/??
comment: /^s*;.*$/
};
var regex = {
section: /^s*[s*([^]]*)s*]s*$/??
param: /^s*([w.-\_@]+)s*=s*(.*?)s*$/??
comment: /^s*[;#].*$/
};
/**
* @param data
* @returns {INI}
*/
exports.parse = function (data) {
var value = new INI();
var lines = data.split(/ | | /);
var section = null;
var comm = null;
lines.forEach(function (line) {
if (regex.comment.test(line)) {
var match = line.match(regex.comment);
comm = match[0];
return;
} else if (regex.param.test(line)) {
var match = line.match(regex.param);
if (section) {
section[match[1]] = match[2];
if(comm)section[match[1]].___comment=comm;
} else {
value[match[1]] = match[2];
if(comm)value.___comment =comm;
}
comm = null;
} else if (regex.section.test(line)) {
var match = line.match(regex.section);
section = value.getOrCreateSection(match[1]);
if(comm)section.___comment=comm;
comm = null;
} else if (line.length == 0 && section) {
section = null;
comm = null;
}
;
});
return value;
}
/**
* ????INI
* @type {Function}
*/
exports.createINI = exports.create = function () {
return new INI();
};
var fs = require('fs');
exports.loadFileSync =function(fileName/*??charset*/){
return exports.parse(fs.readFileSync(fileName?? "utf-8")) ;
}