Tag: json

Async.waterfall,foreach和parsingJSON node.js. 需要一些build议

我的任务是parsing最后100个dota2游戏。 我从jiiin( https://github.com/jiin/dota2api )使用dota 2 API和小型lib, 我所有的,这是一个async.waterfall调用。 喜欢这个: exports.get = function(req, res, next) { var playerID = +req.params.id; var playerCounter = []; var playerInfo = { kills: [], deaths: [], assists: [], last_hits: [], denies: [], hero_damage: [], hero_healing: [], gold_spent: [], kills_number: 0, deaths_number: 0, assists_number: 0 }; async.waterfall([ function getDota2Json(callback) { dota.getByAccountID(playerID, function […]

JSON数据/方括号剥离

正在努力通过async.map合并来自多个数据源的数据。 然而,我有一个新的数据结构的问题,这是由多个文件组合成一个…每个logging周围的额外括号。 这是我正常的JSON文档格式如下: { "_id": "527b16584930484431f054be", "caption": "lucky", "created_time": "1383652572", "full_name": "kkelcie", }, { "_id": "527b16584930484431f054bd", "caption": "Me with all my friends on our day off work. ", "created_time": "1383798277", "full_name": "zeftodeathbitch" } 这是他的方式来自多个查询的新数据格式化: [ { "_id": "52799ef14930484431ed58ed", "caption": "☀", "created_time": "1383698900", "full_name": "andreSDFFSdfazapata" } ], [ { "_id": "5279a7514930484431ed6b2f", "caption": "Clear Lake", "created_time": "1375497332", […]

客户是否在浏览器环境中使用Restify?

我对Restify客户的目的感到困惑: http://mcavage.me/node-restify/#JsonClient 它们本身是build立在Node.js上的,正如服务器位一样。 我是否认为它们并不打算在浏览器中使用? 他们真的是服务器到服务器通信吗? 如果是这样,那么人们如何实现他们的客户端(浏览器)JS代码来调用Restify API? 直接进行GET / POST / PUT / DELETE请求,还是使用其他工具?

如何在html中实现服务器端node.js

我试图让一个人input一些文本,然后把这个variables推到服务器端,然后运行,但是这个函数似乎没有经过。 (我正在运行express和twit作为node.js库)这是调用html的地方: app.get('/', function (req, res){ res.sendfile('./Homepage.html'); }); 这里是函数被调用的地方: app.post('/form', function (req, res) { hash1 = (req.body.textfield), hash2 = (req.body.textfield2), T.get('search/tweets', { q: hash1 + ' since:2013-11-11', count: 5 }, function (err, reply) { console.log(reply) }) res.console.log('done'); }); 这里是html方面的javascript: function testResults (form) { var Hashtag1 = form.hashtag1.value; var Hashtag2 = form.hashtag2.value; //store variables localStorage.setItem('query3', localStorage.getItem('query2')); […]

将Json发送到nodejs服务器

我使用REST nodejs服务器和JavaScript / Zepto客户端开发应用程序。 我试图从我的客户端发送一个JSONstring到我的服务器 这里是客户端代码: $.ajax({ type: 'POST', url: 'http://localhost:3000/request', data: JSON.stringify({test : "test"}), contentType: "application/json; charset=utf-8", dataType: "json", complete: callback, processData : false, success : function(){ console.log("toto"); }, error : function(){ console.log("erreur") } }); 和我的节点代码: app.post('/request', request.request); // request.js exports.request = function(req, res){ console.log(req.body); res.header("Access-Control-Allow-Origin", "*"); res.send("OK"); } 但是我的节点控制台打印这个: {{test : "test"} : […]

从本地数据库检索JSON响应

我试图从本地系统的数据本地浏览器中打印JSON响应 我有我的代码 :: var express=require('express'); var fs=require('fs'); var http=require('http'); var crypto=require('crypto'); var mysql=require('mysql'); var async=require('async'); var app=express(); var connection=mysql.createConnection({ host: 'localhost', user: 'root', database: 'ImagePostingDB' }); connection.connect(); app.set('port',process.env.PORT||7002); app.use('/Details',express.static(__dirname+'/public/images')); app.use(express.bodyParser()); app.get('/DescriptionSortedPrice/',function(request,response){ var name_of_restaurants; async.series( [ // Get the first table contents function ( callback ) { connection.query('SELECT * FROM ImagePostingtable ORDER BY Sl_no', function(err, rows, […]

如何获得复杂的json对象,并在节点js的视图中呈现它?

我有跟在数组中的json 在服务器中,我发送这样的json getTrips: function getTrips(req, res, next){ var url = '/CTB-WS/rest/trips?from='+ req.tripinfo.fromCityId + '&to=' + req.tripinfo.toCityId + '&depart-date=' + req.tripinfo.departDate+ '&pax=1'; console.log(url); rest.get(url).on('complete', function(trips) { if (trips instanceof Error) { console.log('Error:', trips.message); } else { console.log('trips'+ JSON.stringify(trips)); console.log('onward trips'+ JSON.stringify(trips['onwardTrips'])); trips = trips || []; req.trips = trips['onwardTrips']; next(); } }); }, sendTrips: function sendTrips(req, […]

AngularJS对象序列化的缺点

我正在做一个由node.js / mongodb后端服务的angularJS应用程序。 我的服务器提供了一个用于存储和返回JSON对象的rest API。 我的一些mongodb模式有几个ref,在被送达到angularJS应用程序之前,被dynamic地填充。 我的一些对象是“复杂的”,即我有一个包含对象数组的对象,这些对象已经得到了我的用户的引用。 看来,当我使用$资源来更新(PUT)服务器上的这个对象,最后一级的间接不处理。 代替 : { enrollments: [ { price: 100, userProfile: { _id: 'xxxxxxxxxxxxxxxxxxxxxxx' name: "Roger" } } ] } 我有这样的事情: { enrollments: [ { price: 100, userProfile: [Object] } ] } 所以我的更新擦除了我的数据库中有关用户configuration文件的信息。 似乎在第三级之后,串行器停止查找更多数据。 我已经做了一些在AngularJS文档,在计算器上的广泛研究,但无济于事。 当然是因为这个问题的一般性质。 我目前的结论是编写一个自定义的“请求转换”来改变JSON序列化的方式。 但是需要? 有没有更简单的方法来解决这个问题? 谢谢,Stéphane

在parsing节点中的发布数据时遇到问题

这真是让我烦恼。 我有一个节点服务器接收发布数据,parsing它,然后将其作为jsonstring的一部分返回。 但由于某种原因,它不工作。 传入的发布数据格式为: rgb=rgb(xxx%2Cxxx%2Cxxx) 我parsing它,并删除rgb和括号: var str = (querystring.parse(postData).rgb); var str=S(str).replaceAll('%2C', ',').s; var str=S(str).replaceAll('rgb(', '').s; var rgb=S(str).replaceAll(')', '').s; 这留给我:xxx,xxx,xxx 这正是我需要发送到这个JSONstring: hue.light(Light1, function(light){ hue.change(light.set({'rgb':[rgb]})); }); 但它不起作用。 这工作,所以我知道我在正确的轨道上: hue.light(Light1, function(light){ hue.change(light.set({'rgb':[xxx,xxx,xxx]})); }); 有什么types的转换,我需要做的string,使其工作?

节点js表示试图将orm json传递给客户端

在我的app.js question = require('./routes/question_api'), app.use(orm.express("mysql://root@127.0.0.1/daat", { define: function (db, models, next) { var question_model = db.define('questions', { id : Number, ….. more definitions } }); models.question = question_model; next(); } })); 在我的question_api.js var questions = require('../lib/questions/questions.js'); //NEW Question //Get Question by ID //Get Question By Category exports.list = function(req, res){ res.json(questions.list_top_rates(req, res)); }; 在我的questions.js exports.list_top_rates […]