-1

I have a JSON string like the following

    [["Exampe_Level0_1","Exampe_Level1_1","Exampe_Level2_1","Exampe_Level3_1","Exampe_Level4_1","Exampe_Level5_1"],["Exampe_Level0_2","Exampe_Level1_2","Exampe_Level2_2","Exampe_Level3_2","Exampe_Level4_2","Exampe_Level5_2"]]

I also have a class

ExampleClass.h

#import <Foundation/Foundation.h>

@interface ExampleClass : NSObject

@property(nonatomic, strong)NSString *Level0;
@property(nonatomic, strong)NSString *Level1;
@property(nonatomic, strong)NSString *Level2;
@property(nonatomic, strong)NSString *Level3;
@property(nonatomic, strong)NSString *Level4;
@property(nonatomic, strong)NSString *Level5;
@end

Obviously in the JSON string, the first item in array is ExampleClass Level0, second item in array is ExampleClass Level1 etc.

Ideally i want to convert the JSON data into a format into either a NSMutableArray to NSDictionary. Im just lost as to how to convert it.

Thanks

1 Answers1

0

First you convert your string to NSData. Assume the NSString JSONString contains your JSON string:

NSData* JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];

Then convert this data into an NSArray:

NSError *e;
NSArray* finalData = [NSJSONSerialization JSONData options:nil error:&e];

The Object finalData will contain all your elements. Note however that looking at your string it seems as if finalData itself will contain 2 arrays. Those 2 arrays will have your strings

Dhwanit Zaveri
  • 465
  • 1
  • 5
  • 15
  • 1
    Note that the example JSON is not a `NSString`, note that the quote characters are not escaped. – zaph Aug 27 '14 at 21:28