Vivek2012
Vivek2012

Reputation: 772

JSON Parsing not giving Proper NSMutable Array :

I am working on one Webservice app .

They give me response like :

JSON RESPONSE:

{"1":"03:30 PM To 04:30 PM","2":"01:30 PM To 02:30 PM","3":"02:30 AM To 03:30 PM","4":"04:30 PM To 05:30 PM","5":"05:30 PM To 06:30 PM","6":"06:30 PM To 07:30 PM"}

And I want to Show all this TIME intervel with Check box in my another View controller so User can select it .

How do I get this ...

Need help

Upvotes: 0

Views: 82

Answers (3)

Rahul Sharma
Rahul Sharma

Reputation: 3013

You can simply parse the JSON by following Method

NSString* strJSONResponse = @"{\"1\":\"03:30 PM To 04:30 PM\",\"2\":\"01:30 PM To 02:30 PM\",\"3\":\"02:30 AM To 03:30 PM\",\"4\":\"04:30 PM To 05:30 PM\",\"5\":\"05:30 PM To 06:30 PM\",\"6\":\"06:30 PM To 07:30 PM\"}";

NSDictionary* dataDict = [strJSONResponse JSONValue];

NSLog(@"%@",dataDict);

Here is the output:

Printing description of dataDict:
{
    1 = "03:30 PM To 04:30 PM";
    2 = "01:30 PM To 02:30 PM";
    3 = "02:30 AM To 03:30 PM";
    4 = "04:30 PM To 05:30 PM";
    5 = "05:30 PM To 06:30 PM";
    6 = "06:30 PM To 07:30 PM";
}

With this dictionary you can simply make use as per your requirement.

Here you will need to include Required classes for SBJSON found here

I had to add "\" as an escape characters to use it as a string.

Hope it helps

Upvotes: 0

Rajneesh071
Rajneesh071

Reputation: 31081

You can use SBJson classes to parse json data,

here is the like to get all classes

SBJson

Upvotes: 1

Suz
Suz

Reputation: 3802

Check out the documentation for NSArray componentsSeparatedByString:(NSString *). This will separate the Json reply into an array at the string you specify. I would probably use @",".

Upvotes: 2

Related Questions