Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:20:29+00:00 2026-05-30T21:20:29+00:00

I am receiving a JSON response and am currenlty able to make use of

  • 0

I am receiving a JSON response and am currenlty able to make use of the data within my app.

I would like to save this response to a file so I could reference within an JS file located inside my project. I have already requested this data once when the application is launched so why not save it to a file and reference that throughout so only one call is needed for the data.

The HTML files for my UIWebView are imported into my Xcode project using the “create folder reference” option and the path to my JS file is html->js->app.js

I want to save the response as data.json somewhere on the device and then reference inside my js file like this request.open('GET', 'file-path-to-saved-json.data-file', false);

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:20:31+00:00Added an answer on May 30, 2026 at 9:20 pm

    After working with the idea some more here is what I came up with.

    When the application is installed there is a default data file in the package that I copy to the Documents folder. When the application didFinishLaunchingWithOptions runs I call the following method:

    - (void)writeJsonToFile
    {   
    //applications Documents dirctory path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    //live json data url
    NSString *stringURL = @"http://path-to-live-file.json";
    NSURL *url = [NSURL URLWithString:stringURL];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    
        //attempt to download live data
        if (urlData)
        {   
            NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"data.json"];
            [urlData writeToFile:filePath atomically:YES];
        }
        //copy data from initial package into the applications Documents folder
        else
        {
            //file to write to
            NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"data.json"];
    
            //file to copy from
            NSString *json = [ [NSBundle mainBundle] pathForResource:@"data" ofType:@"json" inDirectory:@"html/data" ];
            NSData *jsonData = [NSData dataWithContentsOfFile:json options:kNilOptions error:nil];
    
            //write file to device
            [jsonData writeToFile:filePath atomically:YES];
        }
    }
    

    Then throughout the application when I need to reference the data, I use the saved file.

    //application Documents dirctory path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSError *jsonError = nil;
    
    NSString *jsonFilePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"data.json"];
    NSData *jsonData = [NSData dataWithContentsOfFile:jsonFilePath options:kNilOptions error:&jsonError ];
    

    To reference the json file in my JS code, I added a URL parameter for “src” and passed the file path to the Applications Documents folder.

     request.open('GET', src, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am receiving JSON string response from my WCF service. I wanna parse this
I am receiving an image, title and description from a json file and i
I am using a web service that returns JSON data. test.com/incident.do?JSON&sysparm_action=getRecords Loading this URL
I'm trying to set up jsTree to dynamically accept JSON data from django. This
I am receiving data from state.jsp by JSON and displaying data in auto.jsp in
I'm receiving a JSON response from a web service, but for various reasons I
I am receiving the next JSON response { timetables:[ {id:87,content:B,language:English,code:en}, {id:87,content:a,language:Castellano,code:es}], id:6, address:C/Maestro José
I'm receiving some response from JSON , and is working fine, but I need
I am using jquery-tmpl and receiving the following JSON data, which I am using
I am receiving JSON-Data and convert it into a Dictionary. Printing the Dictionary results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.