gpt4 book ai didi

javascript - JSON 中位置 1 处的语法错误 : Unexpected token .

转载 作者:行者123 更新时间:2023-12-03 00:47:24 24 4
gpt4 key购买 nike

我正在尝试使用较新的 Solidity 来编译和迁移在旧版本的 Solidity 中构建的 Solidity 代码。这是可靠性代码:

//solium-disable linebreak-style
pragma solidity ^ 0.4 .23;

// Simple Solidity intro/demo contract for BlockGeeks Article
contract Geekt {

address GeektAdmin;

mapping(bytes32 => notarizedImage) notarizedImages; // this allows to look up notarizedImages by their SHA256notaryHash
bytes32[] imagesByNotaryHash; // this is like a whitepages of all images, by SHA256notaryHash

mapping(address => User) Users; // this allows to look up Users by their ethereum address
address[] usersByAddress; // this is like a whitepages of all users, by ethereum address

struct notarizedImage {
string imageURL;
uint timeStamp;
}

struct User {
string handle;
bytes32 city;
bytes32 state;
bytes32 country;
bytes32[] myImages;
}

constructor() public payable {
// this is the CONSTRUCTOR (same name as contract) it gets called ONCE only when contract is first deployed
GeektAdmin = msg.sender; // just set the admin, so they can remove bad users or images if needed, but nobody else can
}

modifier onlyAdmin() {
if (msg.sender != GeektAdmin)
revert("invalid message sender: sender not admin");
// Do not forget the "_;"! It will be replaced by the actual function body when the modifier is used.
_;
}

function removeUser(address badUser) public onlyAdmin returns(bool success) {
delete Users[badUser];
return true;
}

function removeImage(bytes32 badImage) public onlyAdmin returns(bool success) {
delete notarizedImages[badImage];
return true;
}

function registerNewUser(string handle, bytes32 city, bytes32 state, bytes32 country) public returns(bool success) {
address thisNewAddress = msg.sender;
// don't overwrite existing entries, and make sure handle isn't null
if (bytes(Users[msg.sender].handle).length == 0 && bytes(handle).length != 0) {
Users[thisNewAddress].handle = handle;
Users[thisNewAddress].city = city;
Users[thisNewAddress].state = state;
Users[thisNewAddress].country = country;
usersByAddress.push(thisNewAddress); // adds an entry for this user to the user 'whitepages'
return true;
} else {
return false; // either handle was null, or a user with this handle already existed
}
}

function addImageToUser(string imageURL, bytes32 SHA256notaryHash) public returns(bool success) {
address thisNewAddress = msg.sender;
if (bytes(Users[thisNewAddress].handle).length != 0) { // make sure this user has created an account first
if (bytes(imageURL).length != 0) { // ) { // couldn't get bytes32 null check to work, oh well!
// prevent users from fighting over sha->image listings in the whitepages, but still allow them to add a personal ref to any sha
if (bytes(notarizedImages[SHA256notaryHash].imageURL).length == 0) {
imagesByNotaryHash.push(SHA256notaryHash); // adds entry for this image to our image whitepages
}
notarizedImages[SHA256notaryHash].imageURL = imageURL;
notarizedImages[SHA256notaryHash].timeStamp = block.number;
// note that updating an image also updates the timestamp
Users[thisNewAddress].myImages.push(SHA256notaryHash); // add the image hash to this users .myImages array
return true;
} else {
return false; // either imageURL or SHA256notaryHash was null, couldn't store image
}
return true;
} else {
return false; // user didn't have an account yet, couldn't store image
}
}

function getUsers() public view returns(address[]) {
return usersByAddress;
}

function getUser(address userAddress) public view returns(string, bytes32, bytes32, bytes32, bytes32[]) {
return (Users[userAddress].handle, Users[userAddress].city, Users[userAddress].state, Users[userAddress].country, Users[userAddress].myImages);
}

function getAllImages() public view returns(bytes32[]) {
return imagesByNotaryHash;
}

function getUserImages(address userAddress) public view returns(bytes32[]) {
return Users[userAddress].myImages;
}

function getImage(bytes32 SHA256notaryHash) public view returns(string, uint) {
return (notarizedImages[SHA256notaryHash].imageURL, notarizedImages[SHA256notaryHash].timeStamp);
}

}

这是完整的错误日志,显示:

> Using network 'development'.
>
> Running migration: 1_initial_migration.js
>
> C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:101723
> var artifact = JSON.parse(
> ^ undefined:1 [.ShellClassInfo] ^
>
> SyntaxError: Unexpected token . in JSON at position 1
> at JSON.parse (<anonymous>)
> at FS.getContractName (C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:101723:25)
> at FS.require (C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:101698:28)
> at Resolver.require (C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:59966:25)
> at Object.require (C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:69602:36)
> at ResolverIntercept.require (C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:197047:32)
> at D:\Cloud\Google Drive\Knowledge Base\Blockchain\Bitcoin\Blockchain Specialization\Smart
> Contracts\Project 1 - Image based Social
> app\Geek\migrations\1_initial_migration.js:1:28
> at ContextifyScript.Script.runInContext (vm.js:59:29)
> at ContextifyScript.Script.runInNewContext (vm.js:65:15)
> at C:\Users\Kombos\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:101639:14
> at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

您能让我知道错误可能是什么吗?提前致谢。

最佳答案

语法错误:意外的标记。在 JSON 中的位置 1 异常可能发生在 JSON 中的无效字符

already answered here

关于javascript - JSON 中位置 1 处的语法错误 : Unexpected token .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com