小编bro*_*lla的帖子

停止python将json文件写入一行

我只是想知道,我如何强制python停止将我的.json文件写入一行?我不知道该怎么办,所以我在这里问.我已经尝试将write命令更改with open('manifest.json', 'wb') as f:with open('manifest.json', 'w') as f:但仍然写入一行?

import json

with open('manifest.json', 'r') as f:
    json_data = json.load(f)
    json_data['server-version'] = "xxxx-x.x.x"

with open('manifest.json', 'w') as f:
    f.write(json.dumps(json_data))

print('Successful.')
Run Code Online (Sandbox Code Playgroud)

如果我在询问时出错,请更正.我是stackoverflow的新手:)

python json

11
推荐指数
1
解决办法
9571
查看次数

无法读取undefined的属性'send'

我正在尝试从外部脚本向路由器发送数据,并返回错误 TypeError: Cannot read property 'send' of undefined

这是代码

app.js

var Cake = require('./modules/cake');

router.get('/cakes', function(req, res) {
  Cake.getCake();
})
Run Code Online (Sandbox Code Playgroud)

cake.js

module.exports = {
  getCake: function (req, res) {
    request({
      url: "http://get.cakes/json",
      json: true
    }, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        res.send(body);
      }
    });
  }
};
Run Code Online (Sandbox Code Playgroud)

请注意,这http://get.cake/不是一个真实的网站.这个问题无关紧要.

javascript node.js express

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

javascript ×1

json ×1

node.js ×1

python ×1