-1

I am getting json data from url as below:

{"message":"success","vendors":[{"businessname":"webixion","vendorid":"67","vendor_city":"kakinda"}]}

How to retrieve all 'message',businessname','vendorid','vendor_id' values

I am using SBJson Framework in Xcode 5 of IOS 7.

Please help me to solve this problem

rmaddy
  • 314,917
  • 42
  • 532
  • 579
lalith222
  • 309
  • 5
  • 16
  • 2
    Why would you still be using SBJSon when you can use Apple [`NSJSONSerialization`](https://developer.apple.com/library/ios/documentation/foundation/reference/nsjsonserialization_class/Reference/Reference.html) – rckoenes Apr 15 '14 at 13:21
  • can u tell me how to use NSJSONSerialization to retrieve json array – lalith222 Apr 15 '14 at 13:23
  • 1
    plese search on google first – Rushabh Apr 15 '14 at 13:23
  • 1
    It does not seem so, but one may want to use SBJson if you need to do SAX style parsing with JSON. If it is not the case, just use NSJSONSerialization as advised. – e1985 Apr 15 '14 at 13:32

1 Answers1

2

I'm not sure if you have a reason to use SBJSON over the native NSJSONSerialization, but the latter is about 5 times faster in my completely unscientific tests.

With NSJSONSerialization, you would do something like this:

    NSURL *url = [NSURL URLWithString:@"http://url/to/file.json"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
Bob Vork
  • 2,927
  • 28
  • 32
  • Although it is a good answer, it is not a good practice to load a `NSData` object from internet using the `dataWithContentsOfURL:`. You should use either [`NSURLConnection`](https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/classes/NSURLConnection_Class/Reference/Reference.html) or [`NSURLSession`](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/Introduction/Introduction.html) to have more control over the data retrieval and error handling. – rckoenes Apr 15 '14 at 13:29
  • You're absolutely right. This is the shortest way I know, but in a live situation you should `NSURLSession` if possible. – Bob Vork Apr 15 '14 at 13:57