2

I have this JSON data:

 {
    "data":{
        "mat_149":{
            "id":"149",
            "title":"The closing of 40% profit within 9 month",
            "teaser":"profit within 9 months only which is equal to 52% annual profit",
            "body":" The auction was presented in a very high and commercial lands.\u000d\u000a",
            "files":{
                "911":{
                    "fid":"911",
                    "filename":"22.JPG",
                    "filepath":"http://mysite/files/22_0.JPG"
                }
            }
        },
        "mat_147":{
            "id":"147",
            "title":"Company launches the city ",
            "teaser":"demands for distinguished lands.",
            "body":" The area size is quare meters This is evident through projects and many other projects.\u000d\u000a\u000d\u000a",
            "files":{
                "906":{
                    "fid":"906",
                    "filename":"2D7z.jpg",
                    "filepath":"http://mysite/dlr/files/2D7Z.jpg"
                }
            }
        },
        "mat_link":"mysite.com/"
    }
}

I'm parsing it like this with the json-framework:

NSString *response = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding] ;
SBJSON *parser = [[SBJSON alloc] init];  
NSDictionary *data = (NSDictionary *) [parser objectWithString:response error:nil];  
NSLog(@"Data : %@", [data valueForKey:@"data"] );

I am getting NULL:

[2599:207] Data : (null)

Can someone point out what I'm doing wrong/how I can fix this?

4
  • Are you sure that receivedData is valid?...and what about NSLog(@"%@",data);?...and maybe the problem is that you have to use SBJsonParser instead SBJSON, have you try this? Commented Jul 16, 2011 at 8:53
  • And is response actually what you expect it to be? Commented Jul 16, 2011 at 8:57
  • yes m very sure that its valid n m getting the full feed in the console window of xcode.... I also want to get the 'file' items .... please help me .... Commented Jul 16, 2011 at 8:59
  • what i should do to get the file items . Please help me .... Commented Jul 16, 2011 at 9:02

1 Answer 1

2

try this one

   NSLog(@"Data : %@", [data objectForKey:@"data"] );

more over

  SBJSON *parser = [[[SBJSON alloc] init] autorelease];//should be release

For his modified questions

    for (NSMutableArray *arr in [data objectForKey:@"data"] ) {



        for (NSMutableArray *arr1 in [arr objectForKey:@"files"]) {


            for (NSMutableArray *arr2 in arr1) {




                NSLog(@"fid : %@ \n\n",[arr2 valueForKey:@"fid"]);

                NSLog(@"filename : %@ \n\n",[arr2 valueForKey:@"filename"]);

                NSLog(@"filepath : %@ \n\n",[arr2 valueForKey:@"filepath"]);


            }


        }


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

4 Comments

M getting the data items , but what i should do to get the 'file' items like 'fid' , 'filname' , 'filepath' .......
how can i get each elements from 'Data' n 'files' and store into some NSStrings ........
NSLog(@"file is : %@", [[[[data objectForKey:@"data"] objectForKey:@"mat_157"] objectForKey:@"files"] objectForKey:@"311"] );
Alabdulkarim[5046:207] -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x7834a40 2011-07-16 14:28:08.923 Ala[5046:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x7834a40'

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.