Having trouble showing JSON data with Ionic 2 and Xcode?

Extracting JSON data from a JSON file in my project and viewing it using "ionic serve" on my Mac has been successful. However, I am facing an issue after building for IOS in XCode. I import the generated project into XCode as usual, but the JSON data is not visible when running in XCode or on my iPhone.

I am using the latest version of all components and working on a Mac.

If anyone can help me identify what I might be doing wrong or missing, I would greatly appreciate it!

Below are snippets of my code:

**src/assets/data/kjv.json**
JSON file location

**src/providers/my-data/my-data.ts:**
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class MyData {

    constructor(public http: Http) {
    }

    getLocalData(){
        return this.http.get('../../assets/data/kjv.json');
    }

}

**src/pages/home/home.ts:**
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { MyData } from '../../providers/my-data/my-data';
import { ChaptersPage } from '../chapters/chapters';

@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})

export class HomePage {

    items: any;

    constructor(public navCtrl: NavController, public myService: MyData) {
    }

    ionViewDidLoad(){
        this.myService.getLocalData().map(res => res.json()).subscribe(data         => {
        this.items = data;
        });
    }

    nextPage(bookNo){
        localStorage.setItem('bookNumber', bookNo);
        this.navCtrl.push(ChaptersPage);
    }

}

**src/app/app.module.ts:**
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';

import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { ChaptersPage } from '../pages/chapters/chapters';
import { VersesPage } from '../pages/verses/verses';
import { TabsPage } from '../pages/tabs/tabs';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { MyData } from '../providers/my-data/my-data';

@NgModule({
    declarations: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    ChaptersPage,
    VersesPage,
    TabsPage
    ],
    imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpModule
    ],
    bootstrap: [IonicApp],
    entryComponents: [
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    ChaptersPage,
    VersesPage,
    TabsPage
    ],
    providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    MyData
    ]
})
export class AppModule {}

Answer №1

The issue was related to the incorrect path of the JSON file. After making this adjustment:

this.http.get('../../assets/data/kjv.json');

was replaced with,

this.http.get('assets/data/kjv.json');

Special thanks to user nuttloose on the ionic forums for the helpful tip!

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 performance of Controller.Json method decreases when working with IQueryable objects

My MVC controller action returns JSON data and currently takes around 2 seconds to complete. I would like it to be faster, ideally under 1 second. After profiling the controller action, I discovered that the line containing the return of JSON is slow, ta ...

Is there a way to execute tagged Feature/Scenario/Examples in Webdriverio-cucumber/boilerplate?

Hey there! I could use some assistance. I'm attempting to execute a specific scenario using Cucumber tags with the expression below: npx wdio run wdio.conf.js --cucumberOpts.tagExpression='@sanity and @stage' However, when I run the comman ...

Transforming a TypeScript enum into an array of objects

My enum is defined in this structure: export enum GoalProgressMeasurements { Percentage = 1, Numeric_Target = 2, Completed_Tasks = 3, Average_Milestone_Progress = 4, Not_Measured = 5 } However, I want to transform it into an object ar ...

When I attempt to conceal the filter within mat-table using *ngIf, I encounter an issue where I am unable to read the property 'value' due to it being

After creating a mat-table, I encountered an issue when trying to show and hide my input filter area using a button. If I use *ngIf="showInputFilter" to hide the filter area, I receive the error message Cannot read property 'value' of u ...

Why doesn't TypeScript automatically determine the prop type when Generics are used?

Below is the code snippet: interface MyInterface { a: { b: { c: "c"; }; }; } type ParentProps = keyof MyInterface type ChildProps<ParentProp extends ParentProps> = keyof MyInterface[ParentProp] type GrandChildType< ...

Is it possible to import a module that was exported in Node.js using the SystemJS import method?

When working on a Node project, we typically import modules using the require keyword. Is it possible to import the same module in an Angular 2 project using import {} from '', even if the d.ts file is not available? For instance, can I incorpora ...

Using Typescript to add an element to a specific index in an array

Currently, I am engaged in a project using Angular2 and Firebase. My goal is to consolidate all query results under a single key called this.guestPush. Within my project, there is a multiple select element with different user levels - specifically 4, 6, ...

Join and Navigate in Angular 2

Attempting to retrieve information from a JSON file has been an issue for me. Here is the code snippet: ngOnInit() { this.http.get('assets/json/buildings.json', { responseType: 'text'}) .map(response => response) .subsc ...

Calculating the mean of JSON data in PostgreSQL

Recently, I received some data in the following format: id heart_rate 1 {0: 28, 1: 25, 2: 38, 3: 42} 2 {0: 30, 1: 28, 2: 43, 3: 58} 3 {0: 42, 1: 29, 2: 98, 3: 38} My goal is to create an object with averaged values that looks somet ...

The creation of the double linked list encountered an assignment error, which is specific to this generic implementation

I have been working on implementing a generic double linked list, and I am facing some errors that are difficult for me to comprehend: https://i.sstatic.net/96gGG.png https://i.sstatic.net/ASKHO.png Although I followed what I believe is the correct appr ...

Ways to transform a String into an Array using Java

Is there a way to convert a String into a String array without relying on a JsonObject in Java? I've searched extensively but haven't found a solution that works for me. The String that I have is similar to: String str="[{"India":{"State":" ...

Is there a way to generate a POJO object based on the provided JSON data?

Looking to create Plain Old Java Objects (POJOs) for the JSON data obtained from the API located at https://developers.google.com/qpx-express/v1/trips/search Encountering an issue when trying to generate POJOs using . An error is triggered at line 5 with ...

Develop an Azure Logic App that automatically generates a JSON format using dynamic variables through an HTTP

Struggling with creating the JSON format for an HTTP Post: Specifically, having trouble concatenating static content with dynamic variables in order to make it work. How can I manually combine what needs to be posted along with variable values? { "colo ...

Transforming instance of a Class into Json format for WebService

My goal is to retrieve an object of the Product class as a Json for a webservice. Despite successfully loading all the values into the object, I encounter an error when trying to return it as Json. Below is my method: <AllowAnonymous> <HttpGet&g ...

What is the process for transforming FormData into an Object and then converting it into a JSON string

Is there a way to convert FormData into an object and then use JSON.stringify on it? I suspect that my API isn't populating values correctly because it expects data in JSON format. handleSubmit: handleSubmit(event) { event.preventDefault(); ...

String Representation of Android View IDs

As I work on creating a Class that will populate my layouts with data from a JSON Schema, I am encountering a challenge. The JSON includes definitions such as { type: "checkbox", label: "Label text", value: true, id: "liquids" }. While rendering the UI is ...

Can the provisioning profile be installed through collaborative access?

After receiving an app from another developer to my dev account, I am unable to access the provision profiles necessary for running it on my iPhone in Xcode. Even though the developer sent me the provision profile file, I still cannot install it. Is there ...

Retrieve all instances of a key-value pair within an object that share the same key

Here is some JSON data: [{"name":"David","text":"Hi"},{"name":"Test_user","text":"test"},{"name":"David","text":"another text"}] I am l ...

Scenario-specific blueprints

I'm currently facing a challenge in incorporating logic into a dustjs template, and I find it challenging to integrate all the components seamlessly. Here is an example of the JSON data I have: { "names": [{ "name": "User 1", "is ...

Encountered issues while trying to utilize wasm function within Vue framework

When attempting to integrate wasm with Vue, I encountered a frustrating issue where the startQuorum function in my wasm file could not be located. import { Go } from './wasm_exec' import quorumWasmUrl from './lib.wasm' export const sta ...