简体   繁体   English

如何将一堆 json 文件合并为一个大文件?

[英]How do I merge a bunch of json files to one big file?

So I have a bunch of json files inside a folder and I want to merge them all into 1 big json file.所以我在一个文件夹中有一堆 json 文件,我想将它们全部合并成 1 个大 json 文件。

So I know you can do this, but I'm not sure how to to add that into a loop so it keeps adding onto 1.所以我知道你可以做到这一点,但我不知道如何将它添加到循环中,以便它不断添加到 1。

var jObject1 = // Your first json object as JObject
var jObject2 = // Your second json object as JObject 

jObject1.Merge(jObject2);

Here is some sample data https://hatebin.com/iuqscvgmqk这是一些示例数据https://hatebin.com/iuqscvgmqk

I've made classes to model the object我已经创建了类来建模对象

But the issue I'm facing is that I don't know how to merge them all into 1 big file, I wanted to use a foreach, kinda like this但是我面临的问题是我不知道如何将它们全部合并到一个大文件中,我想使用 foreach,有点像这样

foreach (var file in Directory.GetFiles("Path"))
            {

            }


 public class Requirements
    {
        public int ranged { get; set; }
    }

    public class Equipment
    {
        public int attack_stab { get; set; }
        public int attack_slash { get; set; }
        public int attack_crush { get; set; }
        public int attack_magic { get; set; }
        public int attack_ranged { get; set; }
        public int defence_stab { get; set; }
        public int defence_slash { get; set; }
        public int defence_crush { get; set; }
        public int defence_magic { get; set; }
        public int defence_ranged { get; set; }
        public int melee_strength { get; set; }
        public int ranged_strength { get; set; }
        public int magic_damage { get; set; }
        public int prayer { get; set; }
        public string slot { get; set; }
        public Requirements requirements { get; set; }
    }

    public class Stance
    {
        public string combat_style { get; set; }
        public object attack_type { get; set; }
        public object attack_style { get; set; }
        public string experience { get; set; }
        public string boosts { get; set; }
    }

    public class Weapon
    {
        public int attack_speed { get; set; }
        public string weapon_type { get; set; }
        public List<Stance> stances { get; set; }
    }

    public class Item
    {
        public int id { get; set; }
        public string name { get; set; }
        public bool incomplete { get; set; }
        public bool members { get; set; }
        public bool tradeable { get; set; }
        public bool tradeable_on_ge { get; set; }
        public bool stackable { get; set; }
        public bool noted { get; set; }
        public bool noteable { get; set; }
        public object linked_id_item { get; set; }
        public int linked_id_noted { get; set; }
        public int linked_id_placeholder { get; set; }
        public bool placeholder { get; set; }
        public bool equipable { get; set; }
        public bool equipable_by_player { get; set; }
        public bool equipable_weapon { get; set; }
        public int cost { get; set; }
        public int lowalch { get; set; }
        public int highalch { get; set; }
        public double weight { get; set; }
        public int buy_limit { get; set; }
        public bool quest_item { get; set; }
        public string release_date { get; set; }
        public bool duplicate { get; set; }
        public string examine { get; set; }
        public string icon { get; set; }
        public string wiki_name { get; set; }
        public string wiki_url { get; set; }
        public Equipment equipment { get; set; }
        public Weapon weapon { get; set; }
    }

If you're trying to combine them as json, you'd need an array.如果您尝试将它们组合为 json,则需要一个数组。 So you'd combine those objects like this:所以你可以像这样组合这些对象:

    var ja = new JArray();
    ja.Add(jObject1);
    ja.Add(jObject2);

You of course could then later convert to your .NET object later if that's what your end goal is.如果这是您的最终目标,您当然可以稍后转换为您的 .NET 对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM