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 8398069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:56:37+00:00 2026-06-09T20:56:37+00:00

I have this simple json file in my iphone/ipad project. {initial_page : Page_Selected} Page_Selected

  • 0

I have this simple json file in my iphone/ipad project.

{"initial_page" : Page_Selected}

Page_Selected is an NSInteger

I want to modify through a UIPickerView the value of the "initial_page". How to do that?

of course I’ve already done the UiPickerWiew selection part and about the json modification, I will write it into the

-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponents:(NSInteger)component{ }

function.

Maybe function that does the job is [[jsonParsed setInteger:row forKey:@"initial_page"] but this way, the debugger returns me “unrecognized selector sent” exception.

I need only the part in which to modify the json parameter with "initial_page" as the key.

anyone can help me?


that’s what I got.

NSError *jsonParsingError = nil;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"json"];
NSMutableDictionary *configJson = [NSJSONSerialization
                JSONObjectWithData:[NSData dataWithContentsOfFile:filePath]
                options:NSJSONReadingMutableContainers error:&jsonParsingError];

[configJson setValue:[NSNumber numberWithInt:row] forKey:@"initial_page"];

NSLog(@"%@",jsonParsingError);

the last line returns me (null), so the json file is ok.

BUT, If I print out [configJson objectForKey:@"inital_page"] then I can see it changes… so, is there a kind of “commit” or “save” command in order to make it persistent?


following suggestions:

NSData * modified = [NSJSONSerialization dataWithJSONObject:configJson options:NSJSONWritingPrettyPrinted error:&jsonParsingError];

[modified writeToFile:filePath options:NSDataWritingAtomic error:&jsonParsingError];
NSLog(@"returned error: %@", [jsonParsingError localizedDescription]);

again, last line returns me (null) but I can’t find any modification in the file


after changes, I can save the modification of the initial_page, but this works only on iPhone/iPad Simulator and not on the real device debugging.

here’s what I do:

if([modified wirteToFile:filePath options:NSDataWritingFileProtectionNone error:&jsonParsingError])
   NSLog(@"writing ok")
else
   NSLog(@"not ok with error :%@",jsonParsinError);

Iphone simulator has no problem with the last 4 lines, but when I run it on physical iPhone, the last NSLog gives:

"not ok with error : Error Domain=NSCocoaErrorDomain Code=513 The Operation Could not be completed. Operation not permitted"

it seems a permission denied in writing the json file.

  • 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-06-09T20:56:39+00:00Added an answer on June 9, 2026 at 8:56 pm

    the problem is solved: the main wrong concept is to write and / or modify files in the main bundle. now I do this in the NSDocumentDirectory

    this way, I get no error and I can read/write the data directly in/from the iPhone.

    I followed this guide: link of course I use json as filter instead pdf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to have this kind of simple JSON data and I could successfully
I imagine this must have a simple answer, but I am struggling: I want
[{name:Mark,Surname:Gaux}] [{Job:2,Type:Office}] I have this JSON echoed by a PHP file on the server
I have a 1GB json file and i want to parse it using simplejson
I have an issue where if my json file looks like this { Numbers:
i have F8 like json file and i want to store and count the
I have this simple piece of code : int a = 1, b =
I have this simple code (for making things shorted, the important bits are probably
I have this simple redirection on my website and it does not rewrite my
I have this simple rule in my Makefile : PP=g++ -std=c++0x %.o: $.cpp $(PP)

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.