在 Solidity 的函数中提交字符串数组的数组时出现错误

发布于 2025-01-19 19:53:46 字数 941 浏览 1 评论 0原文

在混音IDE中收到了此错误消息:交易到国家/地区。StoreaBatchOfCountries错误:错误编码参数:SyntaxError:JSON.PARSE:json line 1列的JSON DATA第1列第1列的意外字符

我的功能应该在将10个字符串的10个阵列的数组存储在国家图映射中。

这是功能代码

  //Function to store a batch of a maximum 10 countries in the Contract at the same time...
  function storeABatchOfCountries(string[6][10] calldata countriesData)
    external
    isOwner
  {
    uint8 _countryCounter;
    for (uint256 i = 0; i < countriesData.length; i++) {
      countriesMap[countriesData[i][5]] = Country(
        countriesData[i][0],
        countriesData[i][1],
        countriesData[i][2],
        countriesData[i][3],
        countriesData[i][4],
        countriesData[i][5],
        true
      );
      _countryCounter++;
    }
    numberOfCountries = _countryCounter;
  }

,这是我提交给它的数据

[
    ["+376", "Europe", "Andorra", "Euro", unicode"
              

Got this error message in Remix IDE : transact to Countriesy.storeABatchOfCountries errored: Error encoding arguments: SyntaxError: JSON.parse: unexpected character at line 1 column 39 of the JSON data

My Function is supposed to take an array of 10 array of 6 string and store them inside the countriesMap mapping.

Here is the function code :

  //Function to store a batch of a maximum 10 countries in the Contract at the same time...
  function storeABatchOfCountries(string[6][10] calldata countriesData)
    external
    isOwner
  {
    uint8 _countryCounter;
    for (uint256 i = 0; i < countriesData.length; i++) {
      countriesMap[countriesData[i][5]] = Country(
        countriesData[i][0],
        countriesData[i][1],
        countriesData[i][2],
        countriesData[i][3],
        countriesData[i][4],
        countriesData[i][5],
        true
      );
      _countryCounter++;
    }
    numberOfCountries = _countryCounter;
  }

And Here is the data I'm submitting to it:

[
    ["+376", "Europe", "Andorra", "Euro", unicode"????????", "AD"],
    ["+971", "Asia", "United Arab Emirates", "Dirham", unicode"????????", "AE"],
    ["+93", "Asia", "Afghanistan", "Afghani", unicode"????????", "AF"],
    [
      "+1268",
      "North America",
      "Antigua and Barbuda",
      "Dollar",
      unicode"????????",
      "AG"
    ],
    ["+1264", "North America", "Anguilla", "Dollar", unicode"????????", "AI"],
    ["+355", "Europe", "Albania", "Lek", unicode"????????", "AL"],
    ["+374", "Asia", "Armenia", "Dram", unicode"????????", "AM"],
    [
      "+599",
      "North America",
      "Netherlands Antilles",
      "Guilder",
      unicode"????????",
      "AN"
    ],
    ["+244", "Africa", "Angola", "Kwanza", unicode"????????", "AO"],
    ["+672", "Antarctica", "Antarctica", "", unicode"????????", "AQ"]
  ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2025-01-26 19:53:46

unicode"

Remove unicode keyword from list items like unicode"????????". Json parser can't encode unicode word. It works only inside solidity code.

As an example consider following contract:

contract Flags {
   string public flag = unicode"????????";

   function setFlag(string memory _flag) public {
       flag = _flag;
   }
}

and following test case in brownie:

from brownie import accounts, Flags

def test_unicode_string_setup():
    contract = Flags.deploy({'from': accounts[0]})
    assert contract.flag() == "????????"

    # no unicode keyword    
    contract.setFlag("????????", {'from': accounts[0]})
    assert contract.flag() == "????????"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文