在 Solidity 的函数中提交字符串数组的数组时出现错误
在混音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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
unicode"
Remove
unicode
keyword from list items likeunicode"????????"
. Json parser can't encodeunicode
word. It works only inside solidity code.As an example consider following contract:
and following test case in
brownie
: