最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: json is not iterable - Stack Overflow

programmeradmin0浏览0评论

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 that body 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
Add a ment  | 

1 Answer 1

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]);
}
发布评论

评论列表(0)

  1. 暂无评论