nodeJs处理json
来源:互联网 发布:中国学术期刊网数据库 编辑:程序博客网 时间:2024/05/17 22:56
返回json
> var http = require('http'); var data = { 'name': ['chao','qin'], 'company': 'lla', 'movies':[{ 'name': "星河战队1", 'type': "太空歌剧" },{ 'name': "星河战队2:掠夺者", 'type': "太空歌剧" },{ 'name': "星河战队3:联邦英雄", 'type': "太空歌剧" },{ 'name': "变形金刚1", 'type': "外星人类型" },{ 'name': "变形金刚2:卷土重来", 'type': "外星人类型" },{ 'name': "变形金刚3:月黑之时", 'type': "外星人类型" },{ 'name': "世界大战", 'type': "外星人类型" }]};var urllib = require('url'); http//创建服务.createServer(function(req,res){ var params = urllib.parse(req.url, true); console.log(params); // 返回文本 // res.write('hello NodeJs'); if (params.query && params.query.callback) { //console.log(params.query.callback); var str = params.query.callback + '(' + JSON.stringify(data) + ')';//jsonp res.end(str); } else { res.end(JSON.stringify(data));//普通的json } // 返回结束 res.end(JSON.stringify(data)); // res.end();})// 端口号.listen(2015);
读取文件返回json
> var http = require('http'); var urllib = require('url'); var fs=require('fs');// fs.writeFileSync('json/baby_visit.json',JSON.stringify({a:1,b:2}));//写var data=JSON.parse(fs.readFileSync('json/baby_visit.json'));//读 http//创建服务.createServer(function(req,res){ var params = urllib.parse(req.url, true); console.log(params); // 返回文本 // res.write('hello NodeJs'); if (params.query && params.query.callback) { //console.log(params.query.callback); var str = params.query.callback + '(' + JSON.stringify(data) + ')';//jsonp res.end(str); } else { res.end(JSON.stringify(data));//普通的json } // 返回结束 res.end(JSON.stringify(data)); // res.end();})// 端口号.listen(2015);
请求json返回json
> var http = require('http');var request = require('request');var urllib = require('url'); var data;request('http://www.strun.club/source/json/user.json', function (error, response, body) { console.log(response); if (!error && response.statusCode == 200) { console.log(body); data = JSON.parse(body); }}) http//创建服务.createServer(function(req,res){ var params = urllib.parse(req.url, true); console.log(params); // 返回文本 // res.write('hello NodeJs'); if (params.query && params.query.callback) { //console.log(params.query.callback); var str = params.query.callback + '(' + JSON.stringify(data) + ')';//jsonp res.end(str); } else { res.end(JSON.stringify(data));//普通的json } // 返回结束 res.end(JSON.stringify(data)); // res.end();})// 端口号.listen(2077);
0 0
- nodeJs处理json
- 【nodejs】服务器处理url请求并返回json数据
- nodejs json格式转换
- nodejs直接返回json
- nodejs json 解析
- nodejs读写json文件
- nodejs:Excel导出json
- NodeJS返回JSON
- nodejs转json数据处理
- nodejs package.json详解
- nodejs输出json
- nodejs 自定义事件处理
- nodejs处理POST请求
- nodejs mongoose 数据库处理
- NodeJs处理post请求
- NodeJS中的错误处理
- NodeJS 双引号的处理
- opencv 图形处理 && nodejs
- AngularJS ng-repeat下使用ng-model
- 赋诗一首
- VS Code 调试Node.js express网站(Visual Studio Code)
- ubuntu下安装UltraEdit
- 取消本地文件夹与SVN服务器的关联
- nodeJs处理json
- PowerDesigner 把Comment复制到name中和把name复制到Comment
- “裸辞”期间不掉价,真相在此!
- 先验概率和后验概率
- iOS-错误集
- luogu2711小行星
- 51Nod - 1035 模拟
- Filter & Listener
- 通过克隆虚拟机来创建多个虚拟机