在Express中使用res.json:
function random(response) { console.log("response.json sets the appropriate header and performs JSON.stringify"); response.json({ anObject: { item1: "item1val", item2: "item2val" }, anArray: ["item1", "item2"], another: "item" });}或者:
function random(response) { console.log("Request handler random was called."); response.writeHead(200, {"Content-Type": "application/json"}); var otherArray = ["item1", "item2"]; var otherObject = { item1: "item1val", item2: "item2val" }; var json = JSON.stringify({ anObject: otherObject, anArray: otherArray, another: "item" }); response.end(json);}


