Tag: json

AWS CloudSearch:的值不能是JSON数组或对象

我有一个int-arraytypes的字段有这个问题。 使用aws-sdk作为Node.js,我通过CloudSearchDomain.uploadDocuments()方法提交文档。 文档的JSON(在searchContentvariables中)是在节点进程中创build的,然后我使用: var params = { contentType: 'application/json', documents: JSON.stringify([searchContent]) }; csd.uploadDocuments(params, function(err, data){ …(callback process)… }); 非string的searchContent对象如下所示: { id: 1, type: 'Product', hash_type_id: 'Product-1', name: 'Test product', description: 'A test product', category: [ 2 ], content: '<some text here>', state: [ 1 ], hash_all: '<some text>' } 并像这样串化: [{"id":1,"type":"Product","hash_type_id":"Product-1","name":"Test product","description":"A test product","content":" <some […]

用吞咽数据吞噬G G

我正在尝试在我的工作stream中使用gulp-jade的gulp-data,但是我得到了一个与gulp-data插件相关的错误。 这是我的gulpfile.js var gulp = require('gulp'), plumber = require('gulp-plumber'), browserSync = require('browser-sync'), jade = require('gulp-jade'), data = require('gulp-data'), path = require('path'), sass = require('gulp-ruby-sass'), prefix = require('gulp-autoprefixer'), concat = require('gulp-concat'), uglify = require('gulp-uglify'), process = require('child_process'); gulp.task('default', ['browser-sync', 'watch']); // Watch task gulp.task('watch', function() { gulp.watch('*.jade', ['jade']); gulp.watch('public/css/**/*.scss', ['sass']); gulp.watch('public/js/*.js', ['js']); }); var getJsonData = […]

将项目中的json文件加载到app.js

如何将项目中的json文件加载到app.js. 我试过了 var j = require('./JSON1'); 但它没有工作。 我想稍后在app.js中使用JSON.stringify函数,并将它的一部分发送给客户端。 任何人都知道如何做到这一点? 谢谢!

JSON转换为使用json2csv nodejs的CSV文件

我新学到了node.js,我想使用json2csv节点模块将JSON对象parsing为CSV文件。 json2csv只支持一个扁平结构,其中字段是json根的直接子项。 我发现如何parsingjson对象到csv文件使用json2csv节点jj模块主题和更改json2csv的createColumnContent函数来读取我的json文件的对象elemet。 但我的json文件有数组元素,是这样的: [ { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }, { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 […]

ExpressJS SyntaxError:意外的标记C

我试图将我的string保存为一个逗号分隔数组,但是当我尝试使用JSON.parse方法时,发送一个post方法并尝试保存logging时收到此错误: SyntaxError: Unexpected token c at Object.parse (native) at router.route.post.get.res.render.blogpost (/Users/user/Desktop/Projects/node/blog/app/routes.js:106:34) 这是我的路线(错误来自blogpost.save): router.route('/admin/posts/create') // START POST method .post(function(req, res) { console.log("New instance"); var blogpost = new Blogpost(); // create a new instance of a Blogpost model blogpost.title = req.body.title; // set the blog title blogpost.featureImage = req.body.featureImage; // set the blog image blogpost.blogUrl = blogpost.title.toLowerCase().replace(/\s+/g,"-"); […]

如何将JSON数组保存到mongodb集合中

我试图将下面的数组保存到我的文档中的mongodb {"Category_Id":"54c9c206e1f512456ada778b","Sub_category_Id":"54c9c24ee1f512456ada778d", "features":[{"specification_field_type":"textbox","specification_name":"color","_id":"551e5f2e3bbe4691142bdeba","__v":0,"$$hashKey":"object:95"}, {"specification_field_type":"textbox","specification_name":"Call Features","_id":"551e616d3bbe4691142bdebf","__v":0,"$$hashKey":"object:97"}]} 这里是我的node.js代码保存mongodb中的后期值 var Category_Id = req.body.Category_Id; var Sub_category_Id = req.body.Sub_category_Id; var features = req.body.features; var property =new db.properties(); property.Category_Id = Category_Id; property.Sub_category_Id = Sub_category_Id; property.features = features; property.save(function (err){ var message = JSON.parse('{"status":"success","message":"Features added"}'); return res.send(200, message); } 尽pipe查询被执行,但是特征信息以这种方式保存 集合模式是 var properties = new Schema({ Category_Id : { type: String}, Sub_category_Id […]

NodeJS …保存JSON到一个variables

我是NodeJS的一个新手,但是我环顾四周,似乎无法find解决我的问题。 我相信这是简单的,但在此先感谢您可以给我所有的帮助! 我试图通过NodeJS做一个简单的JSON刮刀。 我所需要的是将JSON存储到一个variables。 问题是,我正在使用Require,他们的例子只是将其logging到控制台。 我已经尝试添加一个variables后,它login到控制台,但我只是变得不确定。 这里是我的代码下面,这是相当简单至今:) // var jsonVariable; Doesn't work, shown as a test function getJSON(url){ var request = require("request") request({ url: url, json: true }, function (error, response, body) { if (!error && response.statusCode === 200) { console.log(body) // Print the json response //return body; This doesn't work, nor does making a […]

我怎样才能加载使用'loadtest'nodejs模块testing后期API?

我正在使用loadtest nodejs模块来testingnodejs脚本中API的压力testing。 Get调用语法正在工作,但是后调用不。 代码如下。 function optionsObject() { return { url: 'http://localhost:3000/api/v2/signup', maxRequests: 1, concurrency: 1, method: 'POST', contentType: 'applicaton/json', body: { password: 'test', email: 'testobject_1@signup2.com', name: 'kPYgJ6Rg5wnExt8hTXQIHDn2LaCMsytjhQzp' } } } loadtest.loadTest(optionsObject(), function (error, result) { if (error) { console.log('Got an error: %s', error); } else { console.log(result); } }); Results: { totalRequests: 1, totalErrors: 1, […]

parsingJSON并在Angular中显示数据

我在Angular中显示JSON数据时遇到了麻烦。 我成功地将数据从后端发送到前端(Angular),但是我无法显示它们。 我试图模拟JSFiddle类似的情况,虽然我已经从后端准备数据 获取/发送数据 – >后端: //push data to Redis var messages= JSON.stringify( [ { "name": "Msg1", "desc": "desc Msg1" }, { "name": "Msg2", "desc": "desc Msg2" }, { "name": "Msg3", "desc": "desc Msg3" }, { "name": "Msg4", "desc": "desc Msg4" } ]); redisClient.lpush('list', messages, function (err, response) { console.log(response); }); //get from redis and […]

如何填充一个空的json对象

我有一个这样的空json对象 var image, description ; var json = { 0 : { image : " " , description : " " } }; 我想像这样通过循环n来填充,但是这种添加属性的方式是这个错误:“不能设置undefined的属性描述” json[n].description = " nth description"; json[n].image = " nth image"; 最后我想var json是这样的 var json = { 0 : {"image" : "1st image", "description" : "2nd description" } 1 : {"image" : […]