0

This is Apprecord class

@interface AppRecord : NSObject
@property (nonatomic, strong) NSString *appIcon;
@property (nonatomic, strong) NSString * name;
@property (nonatomic, strong) NSString * description;
@property (nonatomic, strong) NSString * location;
@property (nonatomic, strong) NSString * address;
@property (nonatomic, strong) NSString * contacts;
@property (nonatomic, strong) NSString * additional_info;
@property (nonatomic, strong) NSString * image;
@end

and I am parsing json adding to an object of App record class

#import "ParserClass.h"
#import "AppRecord.h"
@interface ParserClass ()

@property (nonatomic, strong) NSArray *appRecordList;
@property (nonatomic, strong) NSData *dataToParse;
@property (nonatomic, strong) NSMutableArray *workingArray;
@property (nonatomic, strong) AppRecord *workingEntry;
@property (nonatomic, strong) NSMutableString *workingPropertyString;
@property (nonatomic, strong) NSArray *elementsToParse;
@property (nonatomic, readwrite) BOOL storingCharacterData;
@end


@implementation ParserClass
- (id)initWithData:(NSData *)data
{
    self = [super init];
    if (self != nil)
    {
    _dataToParse = data;
    }
    return self;
 }

- (void)main
{
    self.workingArray = [NSMutableArray array];
    self.workingPropertyString = [NSMutableString string];
    self.workingArray=[[NSMutableArray alloc]init];

    NSDictionary *allData=[NSJSONSerialization JSONObjectWithData:_dataToParse options:0 error:nil];
    NSLog(@"%@",allData);

    for (NSDictionary *dict in allData)
    {

         NSLog(@"dict====%@",dict);
        self.workingEntry=[[AppRecord alloc]init];

        self.workingEntry.name=[dict objectForKey:@"name"];

        self.workingEntry.description=[dict objectForKey:@"description"];


        self.workingEntry.location=[dict objectForKey:@"location"];


        self.workingEntry.address=[dict objectForKey:@"address"];


        self.workingEntry.contacts=[dict objectForKey:@"contacts"];


        self.workingEntry.additional_info=[dict objectForKey:@"additional_info"];


        self.workingEntry.image=[dict objectForKey:@"image"];

        [self.workingArray addObject:self.workingEntry];

    }

    NSLog(@"WORKING ARRAY========%@",self.workingArray);// Not getting proper value of working array

 self.workingArray = nil;
self.workingPropertyString = nil;
self.dataToParse = nil;
}

@end 

My problem is not getting proper value of working array,it only stores description property,but it should store apprecord object,please help.

OUTPUT

 alldata=

(
            {
            "additional_info" = "lOREN iPSUM";
            address = "1972 Hillview St. Sarasota,FL 34239";
            contacts = 8745674556;
            description = "Very cute place, awesome wait staff, great food.  I am here on vacation and it     was an awesome place to go to after a day relaxing at the beach.";
            id = 1;
          image = "http://..";
        location = "1972 Hillview St. Sarasota,FL 34239";
        name = "Beer Tasting at Hurricane Hanks";
    },
        {
        "additional_info" = gdfgdfg;
        address = "Farrer Place, Sydney, New South Wales, Australia";
        contacts = 3423423423423;
        description = restataurant;
        id = 16;
        image = "http://..";
        location = kolkata;
        name = "mosco ";
    }
)

WORKING ARRAY========(
"Very cute place, awesome wait staff, great food.  I am here on vacation and it was an awesome  place to go to after a day relaxing at the beach.",
restataurant
)
 First object name== Beer Tasting at Hurricane Hanks
3
  • 2
    can you add NSLog(@"%@",allData); result please? Commented Nov 22, 2013 at 5:26
  • 1
    NSLog(@"Location %@",[dict objectForKey:@"location"]); Print this inside the loop and check wether you get the location address properly? Commented Nov 22, 2013 at 5:45
  • NSLog(@"First object name: %@ location: %@", [[self.workingArray objectAtIndex:0]name],[[self.workingArray objectAtIndex:0] location]); If you get this output then you are done with the code Commented Nov 22, 2013 at 6:09

2 Answers 2

3

First you remove 2 time intialization of self.workingArray

And please replace

@property (nonatomic, strong) NSString * description;

deccription with some other name

To know the reason click this link

Sign up to request clarification or add additional context in comments.

Comments

0
for (NSDictionary *dict in allData)
{
AppRecord *createAppRecord=[[AppRecord alloc]init];
//Do some thing
[self.workingArray addObject:createAppRecord];
}

I think it will be helpful to you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.