UPDATE: An Update has been done to JSON Library. It is better you follow this link.
JSON is a lightweight data-interchange format, which is easy for us to read and write. And sadly iPhone has no framework to process and form valid JSON data. But a third party JSON framework is available, which I found to be very useful. It is comes under BSD license. If you are new to JSON, you have made the right decision to use it and use this link to learn about JSON. What you should do to include JSON support in your iPhone Application?
WAY 1:
- Download the latest JSON framework from the link I have provided.
- open the .dmg file and you will get a lot of folders and files. Copy the the SDKs/JSON folder and drop it in to the /Users/USERNAME/SDKs/ .
- In your Project, select your target in the left-hand menu and click the blue Info button (Apple-i) and select the “Build” tab.
- Make sure “All Configurations” is selected in the “Configuration” drop-down.
- Add the following new line to the “Additional SDKs” option: $HOME/Library/SDKs/JSON/${PLATFORM_NAME}.sdk
- Add the following two options to the “Other Linker Flags” option: -ObjC -ljson
- Use ‘#import ‘ in your source files. And thats done.
WAY 2:
There is another obvious way to achieve this. (regardless of the target- iPhone or Mac).
It is including the JSON folder directly in to your project. In this case we need to use
#import “JSON.h” in the source files
EXAMPLE:
A simple way of converting a NSString object (result from web service) to JSON object is shown below:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSData *postData = [url dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; [request setURL:[NSURL URLWithString:kURL]]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; [request setHTTPBody:postData]; NSURLResponse *urlResponse; NSError *error; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; [request release]; NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; SBJSON *jsonParser = [SBJSON new]; returnValue= (NSDictionary*)[jsonParser objectWithString:jsonString]; [jsonParser release]; [jsonString release];
And thats all for this post….Bye
Peter
Aug 25, 2010 @ 14:15:56
Hi
Just about to embark on creating a sql backended web application and want to make some data accessible to iphone, Android phones.
Here’s how my model will work.
1. Enter data into sql table(s) through web interface written in Visual Studio 2010 written in VB
2. Interact with sql through web interface as usual
The above is business as usual, now I want to be able to do the following
3. Interact with data on a read only basis presented to the phone in data tables and/or graphically presented by striking an iphone or similar icon in the phones dashboard(s).
4. Simply put pick up your phone. Get to the screen where my icon will be. Hit the icon and as the result of the user having the right to have the icon present by subscription to my service the user is then presented with access to different menus and then data sent to them by interaction with the sql database.
Having read quite a lot on he net, there seems to be quite a lot that say you have to use a service and others such as yourself that suggest json framework.
Can you help by informing of the steps that are best taken to develope this model, as where I have quite a good idea of writing the sql/vb side, the apple/android side is confusing. Please would you point me in the right direction.
Thanks
Peter
Peter
Aug 25, 2010 @ 14:26:19
Do you have any examples of such a model ?
Peter
Aug 25, 2010 @ 14:44:52
Sorry, have another question for you
Is there a way to develop iPhone apps on a windows machine ?
R
P