admin管理员组文章数量:1318569
The Error
C:\Development\AlphaLauncher-Recode\app\assets\js\loggerutil.js:29 [Launcher] TypeError: json is not iterable
at DistroIndex._resolveInstances (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:260)
at Function.fromJSON (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:253)
at Request._callback (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:327)
at Request.self.callback (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:185)
at Request.emit (events.js:203)
at Request.<anonymous> (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:1161)
at Request.emit (events.js:203)
at IningMessage.<anonymous> (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:1083)
at Object.onceWrapper (events.js:291)
at IningMessage.emit (events.js:208)
This is the error I get when I try to run the launcher that I've made. The source code is not made public yet on my github, however, what I need it to do is grab the distribution index from my dropbox to allow the launcher to load in the instance for the launcher to run.
The code for the request and catch.
exports.DistroIndex;
exports.Types = {
Library: 'Library',
ForgeHosted: 'ForgeHosted',
Forge: 'Forge',
ForgeMod: 'ForgeMod',
File: 'File',
VersionManifest: 'VersionManifest'
}
let data = null;
exports.pullRemote = async function(distroURL) {
return new Promise((resolve, reject) => {
let opts = {
url: distroURL,
timeout: 10000
}
request(opts, (error, _resp, body) => {
if(!error) {
try {
data = DistroIndex.fromJSON(JSON.parse(body));
resolve(data);
}
catch (e) {
reject(e);
}
}
else {
reject(error);
}
});
});
}
exports.getDistribution = function() {
return data;
}
I've been playing around with it for a while, any idea on how to fix this? I've been trying but maybe with a fresh pair of eyes, we can fix the problem together.
This is a minecraft launcher by the way with automatic updates and modded jar downloads.
The Error
C:\Development\AlphaLauncher-Recode\app\assets\js\loggerutil.js:29 [Launcher] TypeError: json is not iterable
at DistroIndex._resolveInstances (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:260)
at Function.fromJSON (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:253)
at Request._callback (C:\Development\AlphaLauncher-Recode\app\assets\js\distromanager.js:327)
at Request.self.callback (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:185)
at Request.emit (events.js:203)
at Request.<anonymous> (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:1161)
at Request.emit (events.js:203)
at IningMessage.<anonymous> (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:1083)
at Object.onceWrapper (events.js:291)
at IningMessage.emit (events.js:208)
This is the error I get when I try to run the launcher that I've made. The source code is not made public yet on my github, however, what I need it to do is grab the distribution index from my dropbox to allow the launcher to load in the instance for the launcher to run.
The code for the request and catch.
exports.DistroIndex;
exports.Types = {
Library: 'Library',
ForgeHosted: 'ForgeHosted',
Forge: 'Forge',
ForgeMod: 'ForgeMod',
File: 'File',
VersionManifest: 'VersionManifest'
}
let data = null;
exports.pullRemote = async function(distroURL) {
return new Promise((resolve, reject) => {
let opts = {
url: distroURL,
timeout: 10000
}
request(opts, (error, _resp, body) => {
if(!error) {
try {
data = DistroIndex.fromJSON(JSON.parse(body));
resolve(data);
}
catch (e) {
reject(e);
}
}
else {
reject(error);
}
});
});
}
exports.getDistribution = function() {
return data;
}
I've been playing around with it for a while, any idea on how to fix this? I've been trying but maybe with a fresh pair of eyes, we can fix the problem together.
This is a minecraft launcher by the way with automatic updates and modded jar downloads.
Share Improve this question asked Apr 26, 2020 at 0:42 AlphineGhostAlphineGhost 231 gold badge1 silver badge7 bronze badges 3- Don't parse it? – Socrates Tuas Commented Apr 26, 2020 at 1:11
-
The error is ing from
DistroIndex.fromJSON
. My guess is thatbody
is expected to be an array but it's an object in this context or you're not supposed to parse it in advance. Can we see the code of DistroIndex? – Elan Hamburger Commented Apr 26, 2020 at 1:14 - pastebin./KHUF8Txg < if you need the distromanager.js and the distro file I can give it you – AlphineGhost Commented Apr 26, 2020 at 2:10
1 Answer
Reset to default 5_resolveInstances(json) {
const arr = [];
for(let s of json) {
arr.push(Instance.fromJSON(s));
}
this.instances = arr;
}
Error from here, for(let s of json)
JSON object can't be iterable.
You can use like this to read JSON object values per key.
for(const key in json) {
console.log(json[key]);
}
本文标签: javascriptTypeError json is not iterableStack Overflow
版权声明:本文标题:javascript - TypeError: json is not iterable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742042891a2417629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论