I am getting following the json response from a web-service api. I want to extract product data from the json. I also want to implement this using AFNetworking.
{"products": [
{
"product_id": "1170",
"name": "zzzz®",
"sort_order": 0,
"brand": "zzzas",
"product_category_id": "1090",
"location_ids": [
"1078"
],
"icon_url": "http://zzzzz.com/media/2502/zzzz.png",
"icon_date": "Wed, 07 Nov 2012 14:03:47 GMT",
"thumbnail_url": "http://zzzz.com/media/2591/zzdfs.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:02 GMT"
},
{
"product_id": "1126",
"name": "ddddd®",
"sort_order": 1,
"brand": "dddsas",
"product_category_id": "1110",
"location_ids": [
"1095"
],
"icon_url": "http://zzzzz.com/media/2507/ddddd.png",
"icon_date": "Wed, 07 Nov 2012 14:03:48 GMT",
"thumbnail_url": "http://zzzzz.com/media/2596/sssds.png",
"thumbnail_date": "Wed, 07 Nov 2012 14:04:05 GMT"
}
]}
Can anyone suggest a way to do this.
me how the things will be done.
Please check the example of AFNetworking https://github.com/AFNetworking/AFNetworking/tree/master/Example
For image downloading, EGOCache & EGOImageLoading may be a good choice https://github.com/enormego/EGOImageLoading
Use JSONModel to parse json into object.
If you are just starting, I'd recommend using RestKit for this task (it makes use of AFNetworking). See an example here.
First, in order to run AFNetworking you will first need to install “CocoaPods“. What is this? CocoaPods is a dependency manager for for Objective-C which makes installing third party libraries as AFNetworking much more faster and secure. It is provided as a Ruby Gem which you can install the following way:
Open up the terminal and execute the following commands:
Be patient. This command can take some time to finish, so the “-V” option will provide you with detailed data what’s going on.
Next we execute:
Which sets up our CocoaPods installation.
Now we have to create a PodFile which will server as our config file for CocoaPods.
Back to the terminal and we write the following commands:
The first command will create a file named “Podfile” with the Unix touch editor. The second line will open this newly created file for editing. By now, you should see an empty TextEdit window opened. Now we paste the following inside this file:
Now it is time to set up our Cocoa working environment. IMPORTANT: Please make sure to change your directory with your terminal at your XCODE PROJECT’S CURRENT DIRECTORY by using the ‘cd’ command in the terminal. Example:
Once you are sure that you are at the proper directory execute the following terminal command:
And then we install the dependencies to our project by writing:
Now, this is an important note: Since you are trying to install a project which was previously not inside your current Xcode project you have to create a Workspace for your current Xcode project (if you have not done this already.) To create a workspace for your Xcode project do the following:
Once you are done, navigate to the directory of your Xcode workspace file and execute the following command:
Now you can just use “import ” at the beginning of any of your files to access the builtin API functionalities of AFNetworking.
Try this.
Update 1: You can try this https://github.com/SSamanta/SSRestClient
Update 2: https://github.com/SSamanta/SSHTTPClient (Using Swift)
Available Pod :
pod 'SSHTTPClient', '~>1.2.2'
To parse JSON with AFNetworking, just create a subclass and add the following during initialization.
Then calling a method like
GET:parameters:completion:
will call the completion block with anNSDictionary
as theresponse
parameter (assuming the JSON is valid).To download the images, assuming you want to display them, check out UIImageView+AFNetworking.