Tag: json

Node.js,Ajax发送和接收Json

使用Ajax,我试图只发送Json数据到节点服务器,不涉及处理,只是在发送时发出警报,并在收到时发出警报: 这是我的html5:简单的button,带有onclick函数来触发函数使用ajax调用 <!DOCTYPE HTML> <html> <head> <script> function send() { //alert("Hello World"); $.ajax ({ type: "post", url: "http://localhost:8000", dataType: "json", contentType: "application/json; charset=UTF-8", data: JSON.stringify({name: "Dennis", address: {city: "Dub", country: "IE"}}) }).done(function ( data ) {alert("ajax callback response:" + data); }); </script> </head> <body> <button onclick="send()">Click Me!</button> </body> </html> 这是我的节点服务器的一部分:用于创build服务器并侦听某些操作 var port = 8000; var […]

如何根据“模式”过滤JSON对象

我使用node.js和express / koa构build了一个RESTful API。 我想过滤JSON数据input – 出于安全原因,以及只有需要的业务特定的属性。 过滤后,业务特定的validation发生。 我如何扔掉不需要的JSON / JS对象属性 – 即属性不在我的数据库架构以及空属性? 根据这个定义架构和filter? 使用例如https://github.com/alank64/json-schema-filter 任何可configuration的过滤可用?

如何通过节点中的mongojs将.json文档插入到mongo服务器

我是新的nodeJS和MongoDB。 我有这个代码: var fs = require('fs'); var mongojs = require('mongojs'); var db = mongojs('monitor', ["configurations"]); fs.readFile('json/object1.json', 'utf8', function (err, data) { if (err) throw err; console.log(data); db.configurations.insert(data, function(err, doc) { console.log(data); if(err) throw err; }); }); 没有任何数据蒙了,我没有错误。 这两个console.log(数据)也打印JSONstring。

如何将json数据导出为带有Nodejs指定格式的pdf文件?

我是一个初学者与nodejs。 我正在写一个程序,它将文本数据从json文件转换为pdf文件:这是我的input文件(input.json) { "Info": { "Company": "ABC", "Team": "JsonNode" }, "Number of members": 4, "Time to finish": "1 day" } 我想用下面的样式将它转换成.pdf(report.pdf)文件。 信息 1.1公司 ABC 1.2团队 JsonNode 成员人数4 时间完成1天 我的问题是: 1:如何将样式从input.json文件更改为report.pdf样式。 2:如何从.json格式转换为.pdf格式。 任何人都可以帮助我 提前致谢!

在Node.js中,模块如何从应用程序的package.json中获取数据?

我有一个模块。 在里面,我想从我的父应用程序的package.json文件中访问数据。 什么是最好的做法呢? 我已经完成了这两个级别,并要求文件(或使用nconfconfiguration加载器)的这种疯狂的方式。 var appdir = path.resolve(__dirname, '../../'); nconf.file('app', path.join(appdir, 'package.json')); 但是,这似乎可以轻松地打破。 另外我听说pkginfo ,它会自动从我自己的模块的package.json中获取信息,但是我正在从父应用程序中获取数据。 谢谢你的帮助! 编辑:我想另一种问的方式是,我怎样才能得到应用程序的path(而不是模块path)?

意外的令牌与有效的JSON?

为什么我不能打印这个简单的JSON? jsonlint.com说这是有效的 JSON: [ { "token_start_offset": "0.00", "token_duration": "4.00", "token_base_start_offset": "0.00", "token_base_duration": "4.00", "token_type": "background_noise", "token_background_noise_type": "other", "session_id": "1459194633575", "token_base_form": "…", "token_print_form": "…", "session_boundary": "begin", "nonspeech_boundary": "begin", "token_id": "0" } ] app.js: var testJson = require('./json'); console.log(testJson); 但是当我运行这个,我得到了下面的错误: 错误: module.js:428 throw err; ^ SyntaxError: C:\Users\Owner\Desktop\format test\json.json: Unexpected token at Object.parse (native) at Object.Module._extensions..json (module.js:425:27) at […]

JSON如何不能保存对象的function?

在我的游戏中,我通过将所有对象转换为JSON并将其保存到文件来保存当前状态。 一些对象,像敌人一样,有它们的function,但JSON不能保存function! 有替代scheme吗?

parsingJSON数组nodejs

所以我正在学习NodeJS和一般的JavaScript,并玩弄它,我有一些parsingJSON的问题。 我从“用户”收到以下内容: { "sync_contact_list": [ { "name": "c", "number": "789", "email": "" }, { "name": "b", "number": "123", "email": "a@a.com" }, { "name": "a", "number": "416", "email": "" } ] } 我的问题是我如何正确parsing这个来获取个人位: { "name": "a", "number": "416", "email": "" } 我一直在尝试做var jsonObject = JSON.parse(req.body); ,但我不断收到parsing错误,不pipe我如何改变我收到的JSON(单个组件,所有的等)。 任何人都可以指出我做错了什么? 编辑:所以我使用快递处理不同的path。 所以我有app.js: var express = require('express') , routes = […]

在节点package.json中,使用额外的参数从另一个脚本调用脚本,在这种情况下添加mocha观察器

在节点的package.json中我想重用一个我已经在'脚本'中的命令。 这是一个实际的例子 而不是(注意观看脚本中的-w ): "scripts": { "test" : "./node_modules/mocha/bin/mocha –compilers coffee:coffee-script/register –recursive -R list", "watch": "./node_modules/mocha/bin/mocha –compilers coffee:coffee-script/register –recursive -R list -w", } 我想有类似的东西 "scripts": { "test" : "./node_modules/mocha/bin/mocha –compilers coffee:coffee-script/register –recursive -R list", "watch": "npm run script test" + "-w", } 这不工作(不能在json中做string连接),但你应该得到我想要的 我知道npm脚本支持: – &(并行执行) – &(顺序执行) 所以也许有另一种select?

在node.js中将xml翻译成json

请指点我一些工作XML – > JSON翻译库node.js? 在xml文件仍在接收的时候,SAX风格将会更好。 谢谢