当前位置:网站首页>d合并json
d合并json
2022-08-02 22:42:00 【fqbqrr】
module combinejsonv3;
import std.file;
import std.stdio;
import std.json;
import std.array;
import std.algorithm.searching;
void main()
{
// 保存位置
JSONValue jsonResult;
jsonResult.array = [];
foreach (string filename; dirEntries(".", "*.json", SpanMode.shallow))
{
// 包含输出,忽略
if(canFind(filename, "output")) {
std.stdio.writeln("ignoring: " ~ filename);
continue;
}
// 按串读
string content = std.file.readText(filename);
// 按JSON解析
JSONValue j = parseJSON(content);
// 数组,则合并
if(j.type == JSONType.array) {
// 显示状态
std.stdio.writeln("processing JSON array from: " ~ filename);
jsonResult.array ~= j.array;
}
}
// 写至文件.
std.file.write("output-combined.json", jsonResult.toPrettyString);
}
可这样:
import std.stdio : writeln;
不与std.file冲突.
或这样:
import std;
void main() {
dirEntries(".", "*.json", SpanMode.shallow)
.filter!(f => !f.name.canFind("output"))
.map!(readText)
.map!(parseJSON)
.fold!((result, json) {
result ~= json.array; return result; })
.toPrettyString
.reverseArgs!(std.file.write)("output-combined.json");
}
边栏推荐
- Find My技术|智能防丢还得看苹果Find My技术
- Shunted Self-Attention via Multi-Scale Token Aggregation
- threejs dynamically adjust the camera position so that the camera can see the object exactly
- The only way to go from a monthly salary of 10k to 30k: automated testing
- 学习基因富集工具DAVID(2)
- 创建型模式 - 抽象工厂模式AbstractFactory
- The CTF command execution subject their thinking
- Auto.js脚本程序打包
- 同一份数据,Redis为什么要存两次?
- 采用QT进行OpenGL开发(三)着色器编程
猜你喜欢
随机推荐
Jmeter二次开发实现rsa加密
【C语言】带头双向循环链表(list)详解(定义、增、删、查、改)
IDEA 重复代码的黄色波浪线取消设置
工业元宇宙的价值和发展
最新真实软件测试面试题分享,收藏了还怕进入不了大厂?
基于STM32的FLASH读写实验含代码(HAL库)
C语言函数详解(2)【函数参数——实际参数(实参)&形式参数(形参)】
Auto.js脚本程序打包
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析
mysql查询表中重复记录
ROS2初级知识(9):bag记录过程数据和重放
Task 4 Machine Learning Library Scikit-learn
The only way to go from a monthly salary of 10k to 30k: automated testing
严格反馈非线性系统基于事件触发的自抗扰预设有限时间跟踪控制
一个很少见但很有用的SQL功能
GameStop NFT 市场分析
MySql查询某个时间段内的数据(前一周、前三个月、前一年等)
Controller层代码这么写,简洁又优雅!
2022暑假牛客多校1 (A/G/D/I)
创建型模式 - 简单工厂模式StaticFactoryMethod









