Take the 2-minute tour ×

When I NSLog the contents of an NSMutableArray I get null. I believe I know what the issue is.

I'm having a bit of trouble trying to figure out how to remove "//" at the beginning of this JSON output. If you load http://www.google.com/finance/info?infotype=infoquoteall&q=AAPL,C into your browser you'll see the "//" at the beginning. I believe that the "//" is what is causing the array to return null. How could I go about removing the two dashes? Below is I have what I've done thus far...

NSString *url = @"http://www.google.com/finance/info?infotype=infoquoteall&q=C,JPM,AIG,AAPL";

NSData* data = [NSData dataWithContentsOfURL: 
            [NSURL URLWithString: url]];

//parse out the json data
NSError* error;
NSMutableArray* json = [NSJSONSerialization 
                  JSONObjectWithData:data //1


NSLog(@"json is %@", json); //returns "json is (null)"
share|improve this question
In your other post (where you unaccepted my answer), danh showed you in the answer you accepted how to do this. I'm not sure it will help, because I did that too, and there was another problem character in the middle of the JSON (there could be others as well) –  rdelmar Jul 25 '12 at 2:27
possible duplicate of JSON returning null –  Josh Caswell Jul 25 '12 at 2:30
Yes danh, was correct to point out that the issue was the "//" and that somehow I should remove the two dashes. However the solution to remove the dashes did not workout. So its become a question of how to remove the dashes rather than why the data is returning null. –  Web Master Jul 25 '12 at 2:31
add comment

1 Answer

up vote 2 down vote accepted

You can try this:

NSData *newData = [data subdataWithRange:NSMakeRange(4, [data length] -4)];

This gets rid of the first four characters. There was a control character the two slashes and a space before the first "[", and this gets rid of those. I tried this but the data still had a flaw in it further on.

share|improve this answer
add comment

Your Answer


