The error message appears as "TypeError: json cannot be iterated

Encountering an Issue

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 IncomingMessage.<anonymous> (C:\Development\AlphaLauncher-Recode\node_modules\request\request.js:1083)
    at Object.onceWrapper (events.js:291)
    at IncomingMessage.emit (events.js:208)

This is the error message that appears when attempting to run the launcher that was created. The source code has not been shared publicly on my github yet; however, the goal is to retrieve the distribution index from my dropbox in order for the launcher to successfully load the instance needed to run.

Examining 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 have been troubleshooting this for some time now. Any suggestions on how to resolve this issue? I have been attempting to fix it on my own, but perhaps with a fresh perspective, we can work together to find a solution.

Just to provide some context, this is a minecraft launcher with features like automatic updates and modded jar downloads.

Answer №1

function resolveInstancesFromJson(jsonData) {
    const instancesArray = [];
    for(let item of jsonData) {
        instancesArray.push(Instance.fromJSON(item));
    }
    this.instances = instancesArray;
}

An issue arises here, as for(let item of jsonData) JSON object cannot be iterated like this. You can use the following method to access JSON object values based on keys.

for(const key in jsonData) {
    console.log(jsonData[key]);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The use of p-message in Angular's PrimeNg library is not permitted

Hey there, I'm having a bit of trouble with the p-message Tag in Angular. I believe I've imported it correctly as shown below. import { MessageModule } from 'primeng/message'; imports: [ .... MessageModule, ... In the ...

What is the most effective way to obtain the final row of a Google DataTable using JavaScript?

I have data for Temperature, Humidity, and Time that I can retrieve from a database table to use in a DataTable. However, I also want to extract the most recent set of values from the DataTable and display them in console.log. After attempting to output c ...

Ionic 2: Unveiling the Flipclock Component

Can anyone provide guidance on integrating the Flipclock 24-hours feature into my Ionic 2 application? I'm unsure about the compatibility of the JavaScript library with Ionic 2 in typescript. I have searched for information on using Flipclock in Ionic ...

Retrieval of each single row from a PHP-generated JSON dataset

This is quite challenging, especially for me. My goal here is to use Javascript to extract each value of every row in this JSON data: {"id":2,"url":"image.png","x":19,"y":10,"user_id":20} {"id":3,"url":"image.png","x":19,"y":10,"user_id":20} {"id":4,"url" ...

Leveraging a JavaScript variable within a PHP snippet

Similar Question: Sending a PHP string to a JavaScript variable with escaped newlines Retrieving a JavaScript variable from PHP I am trying to work with a Javascript function that accepts one variable, having some PHP code embedded within it. I am ...

Testing the equality of nested arrays: A step-by-step guide

My maze generator creates walls for each "cell", resulting in duplicate walls - such as the left wall of one cell being identical to the right wall of the adjacent cell. I have managed to convert the maze data into a different program where it is stored in ...

Verification of version numbers

When it comes to my product version number, it follows the format "P.Q.R", where P, Q, and R are represented by digits. The acceptable inputs include "P", "P.Q", and "P.Q.R". I created a regular expression that involves an OR operation. (^\d+$) | (^ ...

What is the best way to attach an identifier to the URL of an ajax request in Vue.js?

Here is the URL for the page: To obtain JSON data, I am trying to retrieve the id from the URL and append it to my Ajax request. I extracted the id using the following code: var id = window.location.href.split('=').pop() console.log(id) My Vu ...

What steps are involved in implementing Local fonts in theme UI for Next JS?

I am currently developing an application using next JS with [theme-UI][1]. However, I need to implement local or custom fonts in my project and I'm unsure of how to do this. Below is the current theming setup: const theme = { fonts: { ...

What are the steps to create a function that behaves like instanceof when given a string as input

Is there a way to achieve something similar to this? var isChild = isInstanceOf( var1, 'Constructor') so that it is equivalent to var isChild = (var1 instanceof Constructor) The challenge is that the function Constructor is not available in t ...

What are the best practices for implementing and utilizing TransferObjects in Java when applying the DAO pattern?

As per the guidelines in the Core J2EE Patterns, I am implementing a DAO pattern for my project with 3 modules: the core layer, which utilizes the DAO-API layer, that is then implemented by the Service Provider DAO-MySQL layer. The focus of my questions l ...

Having trouble with the functionality of the AngularJS Custom Service?

I have developed a straightforward service as shown below: var app = angular.module('myApp', ['ngRoute']); app.service('UserService', function() { this.user = {firstName:"",middleName:"",lastName:"",email:"",dob:""}; this.ad ...

Creating a fantastic Image Gallery in JavaScript

As I work on creating a basic gallery page with html and css, everything seemed to be running smoothly. However, upon testing it in Google Chrome and IE, the onmouseover function is not responding as expected. The idea is for a larger image to display in t ...

Proper method for updating a component prop in Vue.js from within its method

Here is the code snippet for a Vue.js component: var list = Vue.component('list', { props: ['items', 'headertext', 'placeholder'], template: ` <div class="col s6"> <div class="search"> ...

Encountering an issue with React JS Array Filtering: running into the error message "

I am encountering an error stating that includes is not a function, and the record.id is not being recognized in VS Code. I'm not sure where the problem lies? import React, { Component } from 'react' import axios from "axios" export de ...

Class name that changes dynamically with a specific prefix

I am attempting to dynamically assign ng-model names so that they can be accessed in the controller using '$scope.numbers.no1', '$scope.numbers.no2', and so on. However, my current code is not producing any results: <div ng-repeat=" ...

Having difficulty saving data in database using Ajax request from a Chrome extension

I am currently working on an extension that captures the page URL and saves it in a database once the user clicks the submit button. However, I have encountered a roadblock and believe there might be a missing piece in the extension setup that I cannot pi ...

The skybox boxgeometry fails to appear on the screen, leaving only a blank black display

I'm currently working on a three.js code that involves creating a skybox using a cube with different pictures on each side. However, when I run the file, instead of seeing the cube with the images, all I get is a black screen. I suspect that the issu ...

Java applications have a distinct appearance and vibe that set them apart from the operating system's interface

I have been tasked with making modifications to a Java desktop application, even though I have no prior experience working on Java desktop applications. The project was given to me and I opened it using Netbeans 8.0.2. However, something strange is happen ...

Discovering the element's ID upon clicking a button using Mootools (version 1.1)

There are multiple links with random ids as shown below: <a href="#" class="remove_pid" id="pid_123">Remove 123</a> <a href="#" class="remove_pid" id="pid_234">Remove 234</a> <a href="#" class="remove_pid" id="pid_567">Remove ...