Sending JSON data to a targeted object in iOS

After reading numerous posts on Stack about POSTing data in XML and JSON, I am still having trouble finding specific information on how to update a selected object.

I am successfully retrieving data from my boss' job tracking API and everything seems to be working correctly. However, I now want to update certain variables of individual selected objects.

Imagine this scenario:

Suppose I have a recipe site API where I fetch 100 recipes and display their titles in a table. Upon selecting a row, a new screen appears showing all the recipe details with textfields for updating content and a save button. How can I update an ingredient for the chosen recipe so it reflects on the website?

It's important to note that I am utilizing my company's API and not a server-based database like Parse.com.

Although I prefer using JSON, I am open to exploring XML if there are better solutions available.

New Idea

Do I need to replace the entire object when making updates?

Additional Information

Since I don't have direct links to specific objects due to the API usage, I receive a block of data (100 recipes), convert each object into NSObject, sort them accordingly, and then display the selected object's contents when clicking on a row. This context might be useful in understanding my issue.

The reason for providing this extra context is:

When attempting to update the object via the API, how do I ensure I am only modifying that particular object and not the entire list?

Answer №1

It appears that you are looking to send data via a POST request to populate existing fields:

To achieve this, you can use the following code snippet:

 NSString  *post = [NSString stringWithFormat:@"text_field1=%@",text_field.text];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowingLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:"http://your api to recieve the data into the fields"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];

    if(conn) {
        NSLog(@"Connection Successful");

    } else {
        NSLog(@"Connection could not be established");
    }
    }

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

JavaScript seems to have difficulty correctly parsing objects from JSON

Having trouble populating a Repeat Box with objects from a JSON document. Despite my efforts, it keeps duplicating the first item instead of adding each one individually. Any ideas on what might be causing this issue? Below is the code I am currently usin ...

Retrieve the most recent row from a PHP JSON response

Hey there! I've been attempting to run this code snippet using AngularJS, but all I seem to get is the last row of the dataset. I have come across similar examples on various websites, so I'm not sure if there's a configuration setting that ...

What is the purpose of the jQuery json.text method?

I am working on creating a connect page where users can view content from various social media platforms such as Twitter, Facebook, and YouTube. Currently, I am using the getJson function in jQuery to retrieve data from the Twitter API at . However, I have ...

Using Alamofire and SwiftyJSON subscripts in Swift 3

For some reason, my code isn't working as expected and the result is always nil. I have incorporated Alamofire and SwiftyJSON into my code. Here is a snippet: let urlString = "myurl" let params: Parameters = [ "accessProvider": AccessProvider, ...

Reducing the size of XML files in ASP.NET 3.5 returned from WebMethods: Available solutions

Recently, I've come into possession of an ASP.NET web app built on .NET 3.5, along with its C# client components and a related JavaScript client. The server-side components currently use the default [WebMethod] serialization method, but due to the la ...

Sending an AJAX request to a REST service in order to submit the information captured in an HTML form

<html> <body> <form method="POST"> <label>username</lable> <input id="username" name="username" type="text"> <label>emailid</lable> <input id="emailid" ...

Include JSON elements in the ajaxSubmit function

Here is a snippet of code I am working with: var o_titular = {id:'01',fecha:'2014-01-01'}; var o_dependientes = [ {id:'02',fecha:'2014-02-02'}, {id:'03',fecha:'2014-03-03'} ]; var o_fecha = &apo ...

Discovering the data types of various dictionary values within a JSON file can become a bit tricky when dealing with null values

I am working with a large set of dictionaries from a JSON file, each containing the same keys but different values that can be of multiple types, including null. I need to determine the type of each value so that I can initialize the appropriate variables ...

What is the reason behind appengine-rest-server returning JSON strings instead of integers for properties?

I set up a basic REST server on GAE utilizing the appengine-rest-server. The structure of my database is as follows: SomeString = db.StringProperty() SomeInt = db.IntegerProperty(default=0) SomeFloat = db.FloatProperty(default=-1.0) SomeDateTime = db.Dat ...

Using JSON WebAPI to consume AAD Authentication for Power BI integration

I have developed a unique web service using ASP.NET Core 2 that implements AzureAD authentication and offers a JSON endpoint. My aim is to utilize this web service in Power BI. However, when I select Organizational Account as the authentication method and ...

Using jQuery to interact with a web service - overcoming cross-domain restrictions

Attempting to connect to a WCF service using a jQuery client. Referencing this specific example: http://www.codeproject.com/KB/aspnet/WCF_JQUERY_ASMX.aspx#4 Everything functions properly when the client webpage is on the same domain as the service. Howe ...

How can I set up mixare with JSON data?

$query = "SELECT id, latitude, longitude, elevation, title, distance, has_detail_webpage, webpage, info FROM korban"; $q=mysqli_query($connection, $query); // Assume $connection is the MySQL connection variable //echo $query; while($row=mysqli_fetch_assoc( ...

Sending user input from search component to main App.js in React

I'm currently working on an app that searches a Movies database API. I have a main fetch function in App.js, and in tutorials, people are using a search bar within this main APP component. I'm wondering if it would be better to create a separate ...

Analyze items in two arrays using JavaScript and add any items that are missing

I am working on a JSON function that involves comparing objects in two different arrays, array1 and array2. The goal is to identify any missing items and either append them to array2 or create a new array called newArray1. Here is an example: const arra ...

Utilizing an Angular foreach loop for restructuring JSON data

I currently have an ng-repeat function that outputs arrays of objects in the following format: [ {"day":"10","title":"day","summary":"summary","description":"ok","_id":"53f25185bffedb83d8348b22"}, {"day":"3","title":"day","summary":"summary","description" ...

Is it possible to install a Chrome extension specifically for YouTube on Google Chrome?

Hey, I'm trying to eliminate thumbnail images from YouTube. The code I am currently using is: while (true) { $("ytd-thumbnail").remove() } As of now, when I input this code in the console, it successfully removes all thumbnail images. However, I ...

Extracting data from JSON column using a variable element name

I have a database table with JSON data that I need to decode and store in a relational database. The table is for an Oracle DB 19.0 and it looks like this: CREATE TABLE J_PAGE ( PK_PAGE_ID NUMBER ( 10 , 0 ) , FK_RESP_ID NUMBER ( 10 ...

Obtain the state name after selecting it from the drop-down menu and clicking the submit button (part 3)

Read more about passing city names from PHP to JS in the second part of this discussion on Stack Overflow. This is the JSON data for states ($stateJsonObject): Array ( [0] => stdClass Object ( [stateId] => s1 [stateName] => Kuala Lumpur) ...

When comparing org.json.simple.JSONObject and org.json.JSONObject, the issue of JSONException not being able to be resolved as a

Could someone clarify the distinctions between org.json.simple.JSONObject and org.json.JSONObject? Also, I am encountering an issue with a code that uses org.json.JSONObject and org.json.JSONException. While editing the code in Eclipse (JUNO), it recogniz ...

Switching between languages dynamically with Angular JS using $translateProvider and JSON files

I currently have a collection consisting of 6 different JSON files. en.json es.json fr.json it.json ja.json zh.json An illustration of the data present in each file is as follows (in this instance, considering en.json): { "SomeText": "Test in Englis ...