- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
有没有办法将 JSON 对象转储到文本文件以便从 Node 服务器进行调试?
我正在处理一个非常大的 JSON 对象,其中包含各种其他对象数组。
理想情况下,生成的 txt 文件应该像这样正确格式化
{
type: 'Program',
body: [
{
type: 'VariableDeclaration',
declarations: [
{
type: 'AssignmentExpression',
operator: =,
left: {
type: 'Identifier',
name: 'answer'
},
right: {
type: 'Literal',
value: 42
}
}
]
}
]
}
解决方法:
var fs = require('fs');
var myData = {
name:'bla',
version:'1.0'
}
var outputFilename = '/tmp/my.json';
fs.writeFile(outputFilename, JSON.stringify(myData, null, 4), function(err) {
if(err) {
console.log(err);
} else {
console.log("JSON saved to ");
}
});
最佳答案
如果您的 json 对象称为 json
,您可以使用:JSON.stringify(json, null, 2);
这将为您提供一个字符串,然后您可以转储.
关于javascript - 将 JSON 漂亮地转储到文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20123858/
在通过REST Request Body方法发出搜索请求时,例如 GET /bank/_search { "query": { "match_all": {} }, "sort": [
有没有办法检测用户是否停止滑动?也许 bij 鼠标输入检查之类的。我尝试在 onSliderChange 事件中使用鼠标 isButton0Release 和 hasFocus 来检查用户是否停止滑动
(来源:google.com) 最近,我发现我的应用程序中显示的汉字相当难看。 我想我应该让它们“消除锯齿”。但是,我如何在 Java 中做到这一点? 仅供引用,我没有明确选择要在 GUI 应用程序中
我正在创建一个网站,根据某些条件(即是否登录、是否填写表格等),不同页面的外观可能会有很大差异。这使得需要在不同的时间输出不同的html block 。 但是,这样做会使我的 php 代码看起来很糟糕
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如果我有一个类包含例如几个将用向量填充的槽,那么问题通常会出现。如果我想让这个类的对象或多或少透明,我会为它实现 print-object。在这里我遇到了问题: 如果我在一行中打印所有内容,REPL
我有一个允许上传到我网站的文件扩展名列表。 我用 jQuery Validation plugin 检查它们. 如果他们选择了不受支持的扩展程序,我会显示一条错误消息。 看起来像 var msg =
在一个本身嵌套在一个或多个父数组/结构/union 中的数组/结构/union 中读取多个数字/字符串的最佳方法是什么? 没有临时变量的第一个例子: printf("%d %d\n", a[9][3]
我是 AngularJS 的新手。我目前在为我的观点编写漂亮的 url 时遇到问题。我已经设置了 $locationProvider.html5Mode(true);删除 #从地址栏中显示的网址。但是
我有一个带有 ElasticSearch 的自动完成 jquery 功能。输入第一个字母时出现以下错误。 跨源请求被阻止:同源策略不允许读取 http://localhost:9200/test12/
我是一名优秀的程序员,十分优秀!