Tag: json

对象返回undefined

所以我试图从我从一个网站得到的JSON响应中读取一个值。 我正在尝试从响应中获取clan_name。 这个代码 console.log(JSON.stringify(this.steamFriends.clanStates[groupID])); 其中"103582791438731217"是"103582791438731217" ,返回此对象 { "steamid_clan": "103582791438731217", "clan_account_flags": 3, "name_info": { "clan_name": "Chat Bot Testing & Development", "sha_avatar": { "type": "Buffer", "data": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] } }, "user_counts": { "members": 20, "online": 9, "chatting": […]

angular控制器来检索JSON数据

在这里,我实际上是试图获取json数据,并使用angular度控制器将它们显示在一个玉石模板上。 控制器: processJson.js var getJson = angular.module('getJson', []).controller('controller1', function ($scope, $http) { var url = '/fields/fieldlist'; console.log(url); $http.get(url).success(function (data) { $scope.posts = data; }); }); 这不会parsingjson数组到jade模板 fields.js var express=require('express'); var router =express.Router(); router.get('/fieldlist',function(req,res){ var db=req.db; var collection=db.get('domlist'); collection.find({},{},function(e,docs){ res.json(docs); }); }); module.exports=router; 这成功返回一个json数组对象。 这是我的玉模板 html head body div(ng-app='getJson') div(ng-controller='controller1') div(ng-repeat='post in posts') div(ng-switch-when='text') input(type='text' id='{{post.id}}' […]

通过Ajax请求发送后无法parsingJSON

客户端 在将JSON.stringy应用到对象之后,将它像这样发送到节点服务器(作为POST请求): {"id":"topFolder","parentPath":null,"name":"newProject","is":"root","children":[]} 我通过Polymer的iron-ajax元素在客户端发送请求: <iron-ajax id="ajaxSave" method="POST" url="/save" handle-as="json" on-response="doit" </iron-ajax> 它是用这个函数发送的: save: function() { var v = JSON.stringify(this.data); this.$.ajaxSave.body = v; this.$.ajaxSave.generateRequest(); } 服务器端 然后我尝试在Koa-server上使用JSON.parse请求的正文(使用Koa-Body作为正文parsing器): router.post('/save', body, function*(){ let data = JSON.parse(this.request.body); this.body = "all ok"; }) 我得到一个SyntaxError: Unexpected token o和原始的机构看起来像这样: { '{"id":"topFolder","parentPath":null,"name":"new Project","is":"root","children":': [ '' ] } 为什么收到的身体看起来不同,我该如何解决? 编辑:这是一个完整的curl命令的请求: curl'http :// localhost:3000 / […]

节点JS上的HTTP请求callback

嗨我想通过使用callback方法的http获得响应。 但是我得到一个错误,说callback不是一个函数。 module.exports.ipLookup = function (res, callback) { var http = require('http'); var str = ''; var options = { host: 'ip-api.com', port: 80, path: '/json/', method: 'POST' }; var str= ""; var req = http.request(options, function (res) { res.on('data', function (body) { str += body; }); res.on('end', function () { callback(str); }); }); req.end(); […]

如何通过邮差发送JSON到NodeJS Express服务器?

我试图从Chrome应用程序“邮差”通过POST发送JSON对象。 如果我将头设置为'Content-Type: text/plain' ,那么另一边的输出是一个空对象: {} 如果我将头设置为Content-Type: application/json ,我收到以下响应… '错误:无效的JSON'。 关键是设定ingredients ,其值设定为: { ["name" : "num1", "quantity" : "5"], ["name" : "num2", "quantity" : "2"], [ "name" : "num3", "quantity" : "8"]} 我在这里看到它: router.post('/add', jsonParser, function( req, res ) { if (!req.body) return res.sendStatus(400); console.log( req.body ); });

从JavaScript到nodejs服务器的AJAX POST JSON

我试图发送一个JSON对象从javaScript到node.js服务器。 我使用标准的XMLHttpRequest从JavaScript和标准的node.js代码发送它。 两个代码似乎正在通信,但是node.js总是给我一个空的JSON对象。 我不确定我在做什么错。 这是我的JavaScript代码: <html> <head> <script> function xhrPost() { var data = {"name":"John", "time":"2pm"}; var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.open("POST", "http://[serverIP]:8080/addUser"); xhr.setRequestHeader("cache-control", "no-cache"); xhr.setRequestHeader("content-type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify(data)); } </script> </head> <body onload="xhrPost()"> </body> </html> 这是我的node.js代码: var express = require("express"); […]

如何完全删除JavaScript中的空数组?

我搜查了search,找不到答案,所以如果我是愚蠢的,请接受我的道歉。 我在使用JSON文件作为项目configuration的node.js中构build应用程序。 我正在使用'fs'模块来读取JSON文件,然后我parsing成一个Javascript对象。 然后在使用JSON.stringify将数据写回到文件之前,我修改对象中的细节。 我的问题是,我需要删除一个数组,而不是仅仅清空它,以便在我的界面上正确显示数据: "floors": [ { "floorName": "Grd Floor", "floorNotes": "", "floorPlan": "Buckley_Grd.jpg", "floorWidth": "57.392", "floorHeight": "20.776", "runs": [ [], *<—-I cannot delete these* [] *<—-only empty them* [ { "xCoOrd": "37.88235294117647", "yCoOrd": "59.307359307359306", "drawingType": "node" }, { "xCoOrd": "37.88235294117647", "yCoOrd": "59.307359307359306", "drawingType": "node" }, { "xCoOrd": "48.549019607843135", "yCoOrd": "50", "drawingType": "node" } […]

正确的方式来循环通过JSON对象

由于似乎没有人能够为我的问题find解决scheme ,所以我想以不同的方式提出我的问题:循环访问以下对象的游戏部分的正确方法是什么? [ { "_id": "5710b0ddab8b724011705037", "username": "test", "name": "testuser", "__v": 0, "library": { "games": [ { "platform": [ "17", "94" ], "name": "Simcity", "id": "37620" }, { "platform": [ "146", "20" ], "name": "destiny", "id": "36067" } ], "platforms": [ { "name": "Xbox360", "id": "20" }, { "name": "PC", "id": "94" } ] } […]

DynamoDB和Node Js:意外的令牌h

我试图与DynamoDB竞争Node js亚马逊入门指南。 我试图创build一个表,但这里是我的错误: Unable to create table. Error JSON: { "message": "Unexpected token h", "code": "SyntaxError", "time": "2016-05-06T16:59:50.411Z", "statusCode": 200, "retryable": false, "retryDelay": 0 我正在运行以下节点(直接从亚马逊开始指南): var AWS = require("aws-sdk"); AWS.config.loadFromPath('./.aws/credentials.json'); AWS.config.update({ region: "us-west-2", endpoint: "http://localhost:8000" }); var dynamodb = new AWS.DynamoDB(); var params = { TableName : "Movies", KeySchema: [ { AttributeName: "year", KeyType: "HASH"}, […]

使用Node查询从API查询返回的JSON中的项目

我在我的Node旅程的开始,并写我的第一个小应用程序。 我想从markitondemand.com查询股票代码并返回当前股票价格。 我已经得到了查询和响应工作正常,但我不能解决如何sorting通过返回的数据提取当前价格。 这是我正在运行的代码: var http = require('http'); var options = { host: 'dev.markitondemand.com', port: 80, path: '/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=myFunction', method: 'GET' }; http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log(chunk); }); }).end(); 这是我从服务器收到的数据: myFunction({"Status":"SUCCESS","Name":"Apple Inc","Symbol":"AAPL","LastPrice":100.33,"Change":-0.0799999999999983,"ChangePercent":-0.0796733393088321,"Timestamp":"Fri May 27 15:59:00 UTC-04:00 2016","MSDate":42517.6659722222,"MarketCap":549550050250,"Volume":3169443,"ChangeYTD":105.26,"ChangePercentYTD":-4.68364050921528,"High":100.47,"Low":99.26,"Open":99.49}) 我如何通过search从“LastPrice”中提取100.33:100.33键值对? 我想使用.filters方法,但我不相信是什么被返回是一个格式正确的数组? 谢谢!