【问题标题】:Update JSON object numbers in ascending order in sequence按升序更新 JSON 对象编号
【发布时间】:2022-02-06 05:03:28
【问题描述】:

我的 NFT JSON 文件有问题。由于缺乏设施,我将 10k NFT 集合生成为 10*1000,现在我有 10 个集合(每个 1000)而不是单个集合(10000)。每个集合的 JSON 对象编号为 1-1000。但我想将所有 JSON 对象复制到一个文件中,并按 1-10000 的顺序更新它们的 "edition" 编号。 提前致谢。 这是 NFT 元数据代码。

  "file_path": "ipfs://NewUriToReplace/1.png",
  "nft_name": "NFT #1",
  "external_link": "",
  "description": "NFT Description",
  "collection": "Collection Name",
  "properties": [
    {
      "type": "type",
      "name": "name"
    },
    {
      "type": "type",
      "name": "name"
    },
    {
      "type": "type",
      "name": "name"
    },
    {
      "type": "type",
      "name": "name"
    },
    {
      "type": "type",
      "name": "name"
    }
  ],
  "levels": [],
  "stats": [],
  "unlockable_content": [],
  "explicit_and_sensitive_content": false,
  "supply": 1,
  "blockchain": "Polygon",
  "price": 0.005,
  "quantity": 1,
  "dna": "a2fc94a3a51a7c853c01b553019628907f437d2a",
  "edition": 1,
  "date": 1642499902138,
  "creator": "Artist",
  "seller_fee_basis_points": 250,
  "address": "0x2c41a4e7d9321b1134b076bb0be866709fda6ffb",
  "share": 100,
  "Date": "January 2022",
  "compiler": "HashLips Art Engine"
}```

【问题讨论】:

    标签: json


    【解决方案1】:

    例如,您可以使用 php 读取每个文件,将其附加到数组中,编辑数组然后将其转储到文件中:

    处理json的简单php代码

    $arr = [];
    //scroll trough files (you can use libraries to better do this)
    for($i=0; $i<100; ++i)
        array_push($arr, json_decode(file_get_contents("file$i.json"),true) );
    
    //here $arr contains all the 100 jsons, you can access it as a normal associative array and you can
    //do your stuff
    $arr[100]['esition'] = 'my_edition';
    
    //dump the associative array as to a single file formatted as json
    file_put_contents("outfile.json",json_encode($arr));
    

    【讨论】:

    • 感谢您的回复,但无论如何我都不是编码员或程序员。我无法理解这。可能是我想要一个像这样的解决方案 [stackoverflow.com/questions/13933944/… 由 SlayerCat 提供,它帮助我删除了文件名括号。但与这种情况不同的是,我所有的 json 对象都在一个文件中,并且需要在每个对象中按顺序更新一件事,即版本号。
    • 我认为,如果您不是软件开发人员,StackOverflow 并不是您可以找到答案的最合适的地方
    • 感谢您的告知!我会尽力手动重命名它们。
    【解决方案2】:

    通过 HashLips 艺术引擎的 main.js 设置找到了解决方案。如果你想生成你的 nft 集合不是一步,而是在许多步骤中,例如 10*1000 而不是 10000。在 HashLips 艺术引擎的 main.js 文件的这部分中制作这些。在此代码的第三行和第七行中,将 1 替换为您要开始生成的起始编号。 在这里你可以看到我已经用 1001 替换了 1,所以生成是从 1001 开始的,而不是 1。

      let layerConfigIndex = 0;
      let editionCount = 1001;
      let failedCount = 0;
      let abstractedIndexes = [];
      for (
        let i = network == NETWORK.sol ? 0 : 1001;
        i <= layerConfigurations[layerConfigurations.length - 1].growEditionSizeTo;
        i++
      ) {
        abstractedIndexes.push(i);
      }```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多