これは基本的に私がボットを持っていれば、あなたが書いたものをあなたが書いているIDに基づいて情報を得ることができます。 662というIDを持っていて、それを書いているのなら、それはjsonファイルのsteamIDが662であるかどうかをチェックします。もしそれがあればあなたの通貨とあなたのIDを表示します。JSONファイルをJavascriptで読んで編集する場合
すべて私は考え出した。私の助けが必要なのは、あなたのIDが私のjsonに存在しない場合です。それができないなら、私はそれを新しいものとして創造したい。
これは私のJSONコードです:
{
"tradesettings": {
"pollInterval": 5000,
"confirmationChecker": 10000,
"acceptEscrow": false,
"acceptScammers": false,
"ourmaxitems": 50,
"theirmaxitems": 5
},
"accsettings": {
"amountofaccounts": 3
},
"accounts":[
{ "botID":"3", "steamID":"662", "balance": 0 },
{ "botID":"2", "steamID":"211", "balance": 0 },
{ "botID":"1", "steamID":"76561198026027024x", "balance": 666 },
{ "botID":"0", "steamID":"", "balance": 0 }
]}
そして、私がしたいとき、私は全体の事に
{ "botID":"4", "steamID":"421", "balance": 0 },
を元を追加できるようにしたいので、それは言う:
"accounts":[
{ "botID":"4", "steamID":"421", "balance": 0 },
{ "botID":"3", "steamID":"662", "balance": 0 },
{ "botID":"2", "steamID":"211", "balance": 0 },
{ "botID":"1", "steamID":"951", "balance": 666 },
{ "botID":"0", "steamID":"", "balance": 0 }]
新しいアカウントで新しいIDを作成しました。それ、どうやったら出来るの?? Ohとbtw、私のボットはmyBot.jsにありますが、このjsonファイルはconfig.jsonという同じフォルダです。
これは、これを編集するコードです。
if(ok == 1) {
console.log("[SERVER] "+steamID.getSteamID64()+" is asking for his account information.");
for(r=0;r<= config.accsettings.amountofaccounts ;r++) {
if (config.accounts[r].steamID != "undefined") {
if(config.accounts[r].steamID == steamID.getSteamID64()) {
console.log("[SERVER] "+ steamID.getSteamID64() +" is asking for his account info, respondig with it.\n")
client.chatMessage(steamID.getSteamID64(), "\nDisplaying your account on this bot\nBotID: "+config.accounts[r].botID+"\nSteamID: "+config.accounts[r].steamID+"\nBalance: "+config.accounts[r].balance);
break;
ok = 0;
r = 0;
}
}
if(r == config.accsettings.amountofaccounts) {
console.log("[SERVER] "+steamID.getSteamID64()+" dosen't have an account here, creating one for him.");
client.chatMessage(steamID.getSteamID64(),"Hold on, creating an account.\n\nDone, please type '!account' to view it\n(took 0.03 seconds)");
//var item2={ "botID":config.accsettings.amountofaccounts+1, "steamID":steamID.getSteamID64(), "balance": 0 };
//config.accounts.push(item2)
config.accounts.push({botId: "10", steamID: "11", balance: 0});
break;
r = 0;
ok = 0;
}
}
}
が続いてJSONファイルを別のファイルと呼ばれるconfig.jsonあり
あなたの質問は本当にJSONのようなオブジェクトを変更する方法ではありません。実際には、JavaScriptにファイルを読み書きする方法です。これを行うには多くの方法があります。あなたは、どのような環境で実行しているのか、そして現在そのファイルを読みとっているのか、さらに具体的にする必要があります。 –
私はあなたにプライベートで書くことができる方法はありますか?あなたに見せるためにかなりのコードがあります。 –
いいえ、すべてを公開しておくことが最善です。あなたのコードが独占的なものであれば、あなたの問題を表現するが、秘密の情報を持たない単純化されたバージョンを提供できるはずです。 –