Pages

Labels

Monday, May 14, 2012

JSON web Services in Iphone


JSON is nothing but java web service. We will make rest call to invoke the JSON web services. To parse the data, we should import JSON classes in our application. We can parse the result in connectionDidFinishLoading method. We will see one small example to analyze the parsing function using JSON parser.

9.2  JSON Parsing with Example

         We have to start with Xcode and create a view based application. Now, we have to add JSON classes in to our application, for that right click on the application name and choose Add Files. After adding the Files application will be look as follows,





         You can see  JSON classes in the left pane of Xcode window. Now come back to the header section and import JSON.h file in it.  We have to define UILabel to print the result and NSMutableData to get the result from service. To invoke the action, we have to declare one action in the header section, finally header file will be look as follows,








         Now come to implementation section and define the action.We have to implement the connection for result data in the connection delegates. The code will look as follows,



        
         In connection finish loading file we have to parse data. Here, data will be get as dictionary format, so we have to get desire result by using the keys as follows,



        
         We will get the response data and we have to convert that encoded data as string by using NSUTF8 encoding method. Then we have to store the parse result in one array, for that purpose we  are using latest loans array by getting the JSON value for string.
         Connect the actions and outlets in the xib and build and run the application. We will get the output as follows,









0 comments:

Post a Comment

 
Loading